This is the mail archive of the
newlib@sources.redhat.com
mailing list for the newlib project.
Re: memset (0, 0, 0);
- From: Andreas Schwab <schwab at suse dot de>
- To: Joern Rennecke <joern dot rennecke at superh dot com>
- Cc: gdb at sources dot redhat dot com, newlib at sources dot redhat dot com,bug-glibc at gnu dot org, stephen dot thomas at superh dot com,sean dot mcgoogan at superh dot com
- Date: Fri, 04 Apr 2003 17:21:40 +0200
- Subject: Re: memset (0, 0, 0);
- References: <3E8D9C30.E2CA766E@superh.com>
Joern Rennecke <joern dot rennecke at superh dot com> writes:
|> So, as i understand this, this means that the first argument of memset
|> must point to an object, which contains at least one (the first)
|> character. Passing a NULL pointer, or any other address which is
|> outside the address space of the program, invokes undefined behaviour.
IMHO 7.21.1[#2] gives the definitive answer:
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. 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. On such a
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
call, a function that locates a character finds no occurrence, a
function that compares two character sequences returns zero, and a
function that copies characters copies zero characters.
7.21.6.1 (The memset function) does not say otherwise.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab at suse dot de
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."