From: Florian Weimer <fw@deneb.enyo.de>
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: GNU C Library <libc-alpha@sourceware.org>
Subject: Re: Should memchr work with invalid data size?
Date: Thu, 18 May 2017 05:53:00 -0000 [thread overview]
Message-ID: <8737c2r9to.fsf@mid.deneb.enyo.de> (raw)
In-Reply-To: <CAMe9rOoZfLVq5_K1Nz16FuH50FBHSvE4J3cFysQBYC_Bxpq9sw@mail.gmail.com> (H. J. Lu's message of "Wed, 17 May 2017 15:24:16 -0700")
* 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.
next prev parent reply other threads:[~2017-05-18 5:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-17 22:24 H.J. Lu
2017-05-18 4:22 ` Carlos O'Donell
2017-05-18 5:53 ` Florian Weimer [this message]
2017-05-18 6:42 ` Florian Weimer
2017-05-18 7:42 ` Andreas Schwab
2017-05-18 14:12 ` Adhemerval Zanella
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8737c2r9to.fsf@mid.deneb.enyo.de \
--to=fw@deneb.enyo.de \
--cc=hjl.tools@gmail.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).