PATCH: New 64 bit wcscmp implementation

Joseph S. Myers joseph@codesourcery.com
Fri Sep 16 14:33:00 GMT 2011


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



More information about the Libc-alpha mailing list