[openfirmware] [commit] r2856 - clients/lib
Segher Boessenkool
segher at kernel.crashing.org
Sat Feb 11 02:33:28 CET 2012
> int
> strcmp(const char *s, const char *t)
> {
> + int diff = 0;
> int i;
>
> - for (i = 0; s[i] == t[i]; ++i)
> - if (s[i] == '\0')
> - return (0);
> - return((int) (s[i] - t[i]));
> + for (i = 0; 1; ++i) {
> + diff = s[i] - t[i];
> + if (diff || s[i] == '\0')
> + break;
> + }
> + return(diff);
> }
Neither the old nor the new code is correct: you're supposed
to do the comparison as unsigned char, so that e.g.
strcmp("\x01", "\x81") is negative.
If char is a signed type (and int is more bits than char ;-) )
this code does the wrong thing.
Segher
More information about the openfirmware
mailing list