Return-Path: Delivered-To: apmail-stdcxx-dev-archive@www.apache.org Received: (qmail 81876 invoked from network); 6 May 2008 20:04:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 May 2008 20:04:50 -0000 Received: (qmail 86602 invoked by uid 500); 6 May 2008 20:04:52 -0000 Delivered-To: apmail-stdcxx-dev-archive@stdcxx.apache.org Received: (qmail 86585 invoked by uid 500); 6 May 2008 20:04:52 -0000 Mailing-List: contact dev-help@stdcxx.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@stdcxx.apache.org Delivered-To: mailing list dev@stdcxx.apache.org Received: (qmail 86574 invoked by uid 99); 6 May 2008 20:04:52 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 06 May 2008 13:04:52 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [208.30.140.160] (HELO moroha.roguewave.com) (208.30.140.160) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 06 May 2008 20:03:59 +0000 Received: from nebula.bco.roguewave.com ([10.70.3.27]) by moroha.roguewave.com (8.13.6/8.13.6) with ESMTP id m46K4J6g011840 for ; Tue, 6 May 2008 20:04:19 GMT Message-ID: <4820B9C3.4080703@roguewave.com> Date: Tue, 06 May 2008 14:04:19 -0600 From: Martin Sebor Organization: Rogue Wave Software, Inc. User-Agent: Thunderbird 2.0.0.12 (X11/20080226) MIME-Version: 1.0 To: dev@stdcxx.apache.org Subject: Re: Null src pointer in memcpy? References: <47FEBCEC.20609@roguewave.com> <47FEC186.1050901@roguewave.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Eric Lemings wrote: > > I was just asking because I observed such a call in _rw_bufcat(). > It happens when the printf-like functions in tests/src/printf.cpp > are creating a new buffer for formatting operations. Fix it :) > > Brad. > >> -----Original Message----- >> From: Martin Sebor [mailto:msebor@gmail.com] On Behalf Of Martin Sebor >> Sent: Thursday, April 10, 2008 7:40 PM >> To: dev@stdcxx.apache.org >> Subject: Re: Null src pointer in memcpy? >> >> This is explicitly required in 7.1.4 of C99: >> >> 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. ... >> >> Here's an answer to the same question on comp.lang.c.moderated: >> http://tinyurl.com/6eqo3n >> >> Martin Sebor wrote: >>> Eric Lemings wrote: >>>> >>>> Is it safe to pass a null pointer as the 2nd argument to >> memcpy()? Or >>>> undefined? >>> Assuming the third argument is 0. Strictly speaking I believe it's >>> undefined because memcpy(s1, s2, n) is specified to "copy n bytes >>> from the object pointed to by s2 into the object pointed to by s1" >>> and a null pointer doesn't point to an object. An object is defined >>> as "a region of storage in the execution environment, the contents >>> of which can represent values." >>> >>> AFAIK, most implementations allow null pointers for no-op calls to >>> memcpy() but gcc issues a warning when it detects at compile time >>> that a null pointer is passed as the first or second argument to >>> memcpy(). >>> >>> Martin >>> >>