public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
Cc: Wilco Dijkstra via Libc-alpha <libc-alpha@sourceware.org>,
	 Noah Goldstein <goldstein.w.n@gmail.com>
Subject: Re: [PATCH v2 3/7] string/test-str*cmp: remove stupid_[strcmp, strncmp, wcscmp, wcsncmp].
Date: Mon, 10 Jan 2022 14:16:40 +0100	[thread overview]
Message-ID: <87mtk3yblz.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <AS8PR08MB653493BC26ED5D7510C264A983509@AS8PR08MB6534.eurprd08.prod.outlook.com> (Wilco Dijkstra's message of "Mon, 10 Jan 2022 13:09:21 +0000")

* Wilco Dijkstra:

> Hi Florian,
>
>>>> These implementations are incorrect. There may be a mismatch in s1/s2
>>>> before invalid memory but no null CHAR / length boundary.
>>>
>>> This is not true, see
>>> eg. https://en.cppreference.com/w/cpp/string/byte/strcmp.  Most string
>>> functions require that the string is correctly terminated. There are
>>> only a few exceptions (memchr IIRC), and several generic
>>> implementations use strlen or strnlen before the main loop.
>>
>> I am not sure if those are bugs.  Don't we support non-array usage in
>> these functions as an extension?  At least for strncmp and strnlen and
>> their wide counterparts.  C11 is pretty clear that strncmp operates on
>> arrays, so this is an extension.
>
> My concern is about being able to read beyond a mismatch (which you have
> to anyway when you process more than 1 character per iteration) rather than
> reading beyond the end of a string or array.
>
> What do you mean with non-array usage? Reading beyond the size
> parameter in a strn* function if a NUL terminator has not been found
> yet? Or not stopping at NUL before the size?

strncmp is commonly used as a starts-with-prefix function, as in:

  strncmp (s, "prefix", 6)

This would be the second case: stopping at NUL before the number of
specified bytes are read.

Thanks,
Florian


  reply	other threads:[~2022-01-10 13:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-10 11:42 Wilco Dijkstra
2022-01-10 12:42 ` Florian Weimer
2022-01-10 13:09   ` Wilco Dijkstra
2022-01-10 13:16     ` Florian Weimer [this message]
2022-01-10 13:56       ` Wilco Dijkstra
2022-01-10 18:39 ` Noah Goldstein
2022-01-10 21:38 ` Noah Goldstein
  -- strict thread matches above, loose matches on Subject: below --
2022-01-09 12:29 [PATCH v1 1/5] x86: Optimize strcmp-avx2.S and fix for [BZ# 28755] Noah Goldstein
2022-01-10  0:27 ` [PATCH v2 1/7] x86: Fix __wcsncmp_avx2 in strcmp-avx2.S " Noah Goldstein
2022-01-10  0:27   ` [PATCH v2 3/7] string/test-str*cmp: remove stupid_[strcmp, strncmp, wcscmp, wcsncmp] Noah Goldstein
2022-01-10  0:37     ` H.J. Lu

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=87mtk3yblz.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=Wilco.Dijkstra@arm.com \
    --cc=goldstein.w.n@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).