This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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: Should memchr work with invalid data size?


* H. J. Lu:

> "main memchr" says
>
> The  memchr()  function  scans  the  initial n bytes of the memory area
> pointed to by s for the first instance of c.

POSIX is more clear:

| Implementations shall behave as if they read the memory byte by byte
| from the beginning of the bytes pointed to by s and stop at the
| first occurrence of c (if it is found in the initial n bytes).

This language is not found in C99.

> But test-memchr.c has
>
>       if (pos < len)
>         {
>           size_t r = random ();
>           if ((r & 31) == 0)
>             len = ~(uintptr_t) (p + align) - ((r >> 5) & 31);
>           result = (CHAR *) (p + pos + align);
>         }
>
> which sets len to some random value, like 18446603336355475958.
> Should memchr work with it?

In general, the test is invalid, but it might be a valid test for a
specific implementation.


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