[PATCH] Add cast to unsigned char to strverscmp

Hans-Bernhard Bröker HBBroeker@t-online.de
Fri Nov 8 17:04:30 GMT 2024


Am 08.11.2024 um 12:41 schrieb Christian Franke:
> Corinna Vinschen wrote:
>> On Nov  7 13:58, Joel Sherrill wrote:

>> Given that l and r are unsigned char anyway, the entire expression
>> is unsigned, so there shouldn't be a sign-compare error in newlib's
>> version.

> It's actually signed, IIRC due to changing 'unsigned preserving' (K&R C) 
> to 'value preserving' (C89) implicit conversions.

The reason it's signed is because '1' is a signed integer, so this 
expression has a type train of:

   ((unsigned char) - (signed int)) < (unsigned int)

The left hand side of the < operator is signed int on all but the very 
weirdest architectures (think sizeof(int) == 1), as unsigned char 
undergoes integer promotion to signed int on those.

As to using U'1' to work around this quirk: that's a C11-ism.  YMMV.



More information about the Newlib mailing list