On Fri, May 8, 2009 at 11:21 PM, Bruno Haible <address@hidden> wrote:
> Andreas Schwab wrote:
>> They are free to access the object in any random order they like.
>
> The question is: How many bytes are the mem* functions free to access?
>
> How many bytes is "the object" large?
If s is NULL, there _is_ no object.
> ISO C 99 7.21.5.1 says:
>
> Â "The memchr function locates the first occurrence of c (converted to an
> unsigned
> Â char) in the initial n characters (each interpreted as unsigned char) of the
> Â object pointed to by s.
NULL is not a pointer to an object. A program which passes NULL to
memchr() has undefined behaviour. SIGSEGV is the lucky outcome here;
the compiler is allowed to pour gasoline in your coffee instead of
producing an executable if it likes. See section 3.4.3 of the
standard.
>
> Â Returns
> Â The memchr function returns a pointer to the located character, or a null
> pointer
> Â if the character does not occur in the object."
>
> Can you give a justification why the function would be allowed to access more
> than
> n bytes?
The question doesn't arise, though.
You're talking about the range of reasonable behaviours applying in
circumstances where the C standard imposes no requirements at all.
James.