Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 08 Jun 2012 09:05:26 -0500 Message-ID: <4FD206A5.32BA@mindspring.com> Date: Fri, 08 Jun 2012 10:05:25 -0400 From: pete Reply-To: pfiland@mindspring.com Organization: PF X-Mailer: Mozilla 3.04Gold (WinNT; I) MIME-Version: 1.0 Newsgroups: comp.lang.c Subject: Re: copy size References: <03c3ed4d-f3ce-437b-9476-1c512c7772de@o3g2000pby.googlegroups.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 48 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.156.228.2 X-Trace: sv3-u6raqN3U9Vg4KiCSO4zjw3QF33aU+u341Rv/BZN3JfYTYyfkVKWK/U5973rcwk2+nmn1BhDbtHI9wJe!/DFOZ4X9g1P7jf+1fCTsHmWSYWQw1tnEk5mprbUOgPII11hubzfIPfCIiVjkC3OkBtMrNvReUBev!P0Erje49 X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2669 Xref: csiph.com comp.lang.c:21956 Keith Thompson wrote: > > sinbad writes: > > is it ok to allow memcpy () to take size 0; > > or is it a good practice to check for the size > > and do memcpy only for sizes greater than 0; > > See section 7.24.1 of the C standard > (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf > is the latest draft): > > Where an argument declared as size_t n specifies the length of the > array for a function, n can have the value zero on a call to that > function. > > So yes, it's ok to call memcpy() with a size of 0. > > Note that if either s1 or s2 is a null pointer, the behavior is (I > believe) undefined. You believe correctly. Here is the next sentence from n1570: Unless explicitly stated otherwise in the description of a particular function in this subclause, pointer arguments on such a call shall still have valid values, as described in 7.1.4. And here is some of 7.1.4: 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. -- pete