This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: PATCH: New 64 bit wcscmp implementation
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Dmitrieva Liubov <liubov dot dmitrieva at gmail dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Fri, 16 Sep 2011 14:23:34 +0000 (UTC)
- Subject: Re: PATCH: New 64 bit wcscmp implementation
- References: <CAHjhQ92-2K42N+jrB3nnqUaLoRixjb_F_4GskRr=azD+7BtvHg@mail.gmail.com><Pine.LNX.4.64.1108291509540.17624@digraph.polyomino.org.uk><CAHjhQ93YQnpw8-X8H8ck_P9RsTLrjgRP_0B7J3RGVGTkWzBDYg@mail.gmail.com>
On Fri, 16 Sep 2011, Dmitrieva Liubov wrote:
> Hello,
>
> The example mentioned by Joseph doesn't show that for old wcscmp
> version the comparisons are always done in an unsigned type even when
> wchar_t is signed.
Well - it compares in an unsigned type then subtracts in an unsigned type
and returns the result in a signed type (the sign after conversion to
signed possibly being wrong). The precise form of the bug isn't
particularly significant.
In properly fixed testcases, UCHAR (the type for the comparison) should be
wchar_t not uint32_t in the wide-character case, and the return value in
STUPID_STRCMP etc. can't be determined directly by a subtraction that
might overflow, it needs to be of the form (a < b ? -1 : a == b ? 0 : 1)
or similar.
--
Joseph S. Myers
joseph@codesourcery.com