Source-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS commit: src/lib/libc/stdlib



Module Name:    src
Committed By:   kre
Date:           Tue Nov 17 09:22:59 UTC 2026

Modified Files:
        src/lib/libc/stdlib: strfmon.c

Log Message:
PR lib/60677  strfmon() gcc lunacy fix

Deal with gcc stupidity when chars are unsigned.

If I need to check that a char pointer points to a
char that is between 0 and N (for any N <= 127)
I should be able to just write

        if (*p >= 0 && *p <= N)

and on signed char hosts, that works just fine.
On unsigned char hosts, the test *p >= 0 is
always true, so gcc decides I don't know what I
am doing, and complains.

Idiotic.   It is irrelevant if *p can never be < 0
on such a host, the code is still correct, does exactly
what is needed, and ...

Even worse, I knew this was a possible insanity, and
attempted to guard against it, by converting *p to
an int (with a cast), before doing the comparison.
Surely it is OK to test an int for not being < 0 ?
No... gcc is just too smart for that.   Obnoxious code.

So instead, on all hosts, we need to put up with ugly,
and stupid code, that runs slower, when all that was
needed was for gcc to optimise out the test that can't
fail on hosts where that was true.

This should fix the builds on unsigned char hosts.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/lib/libc/stdlib/strfmon.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.




Home | Main Index | Thread Index | Old Index