Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Paul Pluzhnikov <ppluzhnikov@google.com>
To: Andreas Schwab <schwab@redhat.com>
Cc: Pedro Alves <pedro@codesourcery.com>,
	gdb-patches@sourceware.org,
	        Jan Kratochvil <jan.kratochvil@redhat.com>
Subject: Re: [patch] Fix for PR gdb/10819
Date: Thu, 22 Oct 2009 15:34:00 -0000	[thread overview]
Message-ID: <8ac60eac0910220833v96b75i379486328b8f7955@mail.gmail.com> (raw)
In-Reply-To: <m38wf3it2g.fsf@hase.home>

On Thu, Oct 22, 2009 at 4:09 AM, Andreas Schwab <schwab@redhat.com> wrote:

> Note that this is what the C standard requires.  Even if the number of
> elements is zero all pointer arguments must still be valid.

Specifically:

<quote>

In ISO/ IEC 9899:TC2 Committee Draft — May 6, 2005 WG14/N1124:

7.20.5 Searching and sorting utilities

1 These utilities make use of a comparison function to search or sort
arrays of unspecified type. Where an argument declared as size_t nmemb
specifies the length of the array for a function, nmemb can have the
value zero on a call to that function; the comparison function is not
called, a search finds no matching element, and sorting performs no
rearrangement. Pointer arguments on such a call shall still have valid
values, as described in 7.1.4.

And:

7.1.4 Use of library functions

1 Each of the following statements applies unless explicitly stated
otherwise in the detailed descriptions that follow: If an argument to
a function has an invalid value (such as a value outside the domain of
the function, or a pointer outside the address space of the program,
or a null pointer, or a pointer to non-modifiable storage when the
corresponding parameter is not const-qualified) or a type (after
promotion) not expected by a function with variable number of
arguments, the behavior is undefined. If a function argument is
described as being an array, the pointer actually passed to the
function shall have a value such that all address computations and
accesses to objects (that would be valid if the pointer did point to
the first element of such an array) are in fact valid.

</quote>

There appear to be quite a few qsort calls, and for a few I looked at
it's not immediately obvious that they pass a valid pointer when
nmemb==0 or that nmemb!=0.

I'll just fix the bsearch calls, since A) one of them is known to
cause a problem and B) I introduced them recently :-(

Thanks,
-- 
Paul Pluzhnikov


  reply	other threads:[~2009-10-22 15:34 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-22  4:48 Paul Pluzhnikov
2009-10-22  5:48 ` Jan Kratochvil
2009-10-22  6:14   ` Paul Pluzhnikov
2009-10-22 10:43     ` Pedro Alves
2009-10-22 11:09       ` Andreas Schwab
2009-10-22 15:34         ` Paul Pluzhnikov [this message]
2009-10-22 16:30           ` Paul Pluzhnikov
2009-10-22 17:44             ` Tom Tromey
2009-10-22 18:31               ` Paul Pluzhnikov
2009-10-22 20:13                 ` Tom Tromey
2009-10-22 20:46                   ` Paul Pluzhnikov
2009-10-22 18:11     ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8ac60eac0910220833v96b75i379486328b8f7955@mail.gmail.com \
    --to=ppluzhnikov@google.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    --cc=pedro@codesourcery.com \
    --cc=schwab@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox