From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5456 invoked by alias); 22 Oct 2009 15:34:04 -0000 Received: (qmail 5446 invoked by uid 22791); 22 Oct 2009 15:34:03 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.45.13) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 22 Oct 2009 15:33:59 +0000 Received: from spaceape13.eur.corp.google.com (spaceape13.eur.corp.google.com [172.28.16.147]) by smtp-out.google.com with ESMTP id n9MFXu9U031791 for ; Thu, 22 Oct 2009 08:33:57 -0700 Received: from yxe5 (yxe5.prod.google.com [10.190.2.5]) by spaceape13.eur.corp.google.com with ESMTP id n9MFXrjV007209 for ; Thu, 22 Oct 2009 08:33:54 -0700 Received: by yxe5 with SMTP id 5so4107038yxe.24 for ; Thu, 22 Oct 2009 08:33:53 -0700 (PDT) MIME-Version: 1.0 Received: by 10.101.9.15 with SMTP id m15mr5767356ani.94.1256225633018; Thu, 22 Oct 2009 08:33:53 -0700 (PDT) In-Reply-To: References: <8ac60eac0910212148w24f44d53xfa6bedd7e12b41d1@mail.gmail.com> <20091022054758.GA15116@host0.dyn.jankratochvil.net> <8ac60eac0910212314h3517ff9btcad84f8d0978bddb@mail.gmail.com> <200910221142.55021.pedro@codesourcery.com> Date: Thu, 22 Oct 2009 15:34:00 -0000 Message-ID: <8ac60eac0910220833v96b75i379486328b8f7955@mail.gmail.com> Subject: Re: [patch] Fix for PR gdb/10819 From: Paul Pluzhnikov To: Andreas Schwab Cc: Pedro Alves , gdb-patches@sourceware.org, Jan Kratochvil Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-10/txt/msg00521.txt.bz2 On Thu, Oct 22, 2009 at 4:09 AM, Andreas Schwab wrote: > Note that this is what the C standard requires. =A0Even if the number of > elements is zero all pointer arguments must still be valid. Specifically: In ISO/ IEC 9899:TC2 Committee Draft =97 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. 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=3D=3D0 or that nmemb!=3D0. 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, --=20 Paul Pluzhnikov