This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: memset (0, 0, 0);


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."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]