Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #173803

Re: Can we lie to memchr?

From Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups comp.lang.c
Subject Re: Can we lie to memchr?
Date 2023-09-03 11:22 -0700
Organization A noiseless patient Spider
Message-ID <86r0nfqfql.fsf@linuxsc.com> (permalink)
References <20230903104255.310@kylheku.com>

Show all headers | View raw


Kaz Kylheku <864-117-4973@kylheku.com> writes:

> You would think that memchr can be used to test whether a string is
> longer than N without traversing it.  For instance we can take a
> gigabyte-long character string and efficiently test wheether it is
> shorter than 10 characters:
>
>   memchr(gigastr, 0, 10) == 0
>
> if a null is found within the first 10 bytes, then its length
> is 10 or more.
>
> But suppose a 7 byte string is passed (length 6).
>
> That *object* is smaller than n;  it does not have an "initial sequence
> of n characters" for memchr to search.
>
> ISO C doesn't say that bytes of the initial sequence which are
> beyond are sought-after value shall not be accessed by memchr.  [...]

It does, and has for more than 10 years.

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Can we lie to memchr? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-09-03 17:59 +0000
  Re: Can we lie to memchr? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-09-03 11:22 -0700
    Re: Can we lie to memchr? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-09-03 18:58 +0000
  Re: Can we lie to memchr? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-09-03 19:30 +0100

csiph-web