Re: [PATCH] strcmp: fix overflow error

From: Andreas Schwab
Date: Tue Nov 17 2009 - 12:37:22 EST


Uwe Kleine-KÃnig <u.kleine-koenig@xxxxxxxxxxxxxx> writes:

> strcmp("\x01", "\xef") returns 18 but it should return something < 0.
> The reason is that the variable holding the result of the subtraction is
> too small and overflows.

When char is signed strcmp("\xef", "\x01") still returns something < 0.
You need to cast to unsigned char first.

Andreas.

--
Andreas Schwab, schwab@xxxxxxxxxx
GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84 5EC7 45C6 250E 6F00 984E
"And now for something completely different."
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/