Return-Path: Delivered-To: apmail-stdcxx-dev-archive@www.apache.org Received: (qmail 87792 invoked from network); 11 Apr 2008 01:40:55 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 11 Apr 2008 01:40:55 -0000 Received: (qmail 40436 invoked by uid 500); 11 Apr 2008 01:40:56 -0000 Delivered-To: apmail-stdcxx-dev-archive@stdcxx.apache.org Received: (qmail 40421 invoked by uid 500); 11 Apr 2008 01:40:56 -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 40412 invoked by uid 99); 11 Apr 2008 01:40:56 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Apr 2008 18:40:56 -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: domain of msebor@gmail.com designates 209.85.200.174 as permitted sender) Received: from [209.85.200.174] (HELO wf-out-1314.google.com) (209.85.200.174) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Apr 2008 01:40:05 +0000 Received: by wf-out-1314.google.com with SMTP id 27so271576wfd.2 for ; Thu, 10 Apr 2008 18:40:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:organization:user-agent:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; bh=V6A3WMYSKdkRgg+30dB4d34BUpIFvE03r+TL3nZZFoc=; b=ghpCIQ9kJArzNdBVN4SiJM9MrLt4hB53uM3OqwN7cCJMe0G39LyWnPWiP+AkmRxFUrCvuE7S8IM7EAuiCPE/6s3L56sYIjdmceJ0UGzoH2/4bUkCoB6zQaq8+vP/YTScIrjamDfJNpIWP5+2X71UB0fCh4TdEc0Qh4ChXQpWkAM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:organization:user-agent:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=qLnJ2cIiH9g+vmZmG4vc0Uv31Puw8OE2QhbvWyOCJc/5WeDGQiA9kRdQzIoOPfQb6BJryakLog1/vnHVg36R8EW4i9tpxUdSa20qzN518S9SrxNCWBVL/KhDdPI3ntacxsY8ah8OvXJNB/yUoYOn0rVScGt/frP3ZA4JIyzzwbs= Received: by 10.142.12.18 with SMTP id 18mr643914wfl.268.1207878025402; Thu, 10 Apr 2008 18:40:25 -0700 (PDT) Received: from localhost.localdomain ( [71.229.200.170]) by mx.google.com with ESMTPS id 29sm4003345wfg.9.2008.04.10.18.40.23 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 10 Apr 2008 18:40:23 -0700 (PDT) Message-ID: <47FEC186.1050901@roguewave.com> Date: Thu, 10 Apr 2008 19:40:22 -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> In-Reply-To: <47FEBCEC.20609@roguewave.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Sender: Martin Sebor X-Virus-Checked: Checked by ClamAV on apache.org 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 >