From: Bruno Haible Date: Sat, 22 Jul 2006 14:36:52 +0000 (+0000) Subject: Don't assume that UCHAR_MAX <= INT_MAX. X-Git-Tag: 0.16.x-branchpoint~355 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f7ea484c40020d8f2bd0d196d5f85f3c412d57ae;p=thirdparty%2Fgettext.git Don't assume that UCHAR_MAX <= INT_MAX. --- diff --git a/gettext-tools/lib/ChangeLog b/gettext-tools/lib/ChangeLog index 5d981a6b8..e797373b8 100644 --- a/gettext-tools/lib/ChangeLog +++ b/gettext-tools/lib/ChangeLog @@ -1,5 +1,9 @@ 2006-07-22 Bruno Haible + * c-strcasecmp.c: Update from gnulib. Don't assume that + UCHAR_MAX <= INT_MAX. + * c-strncasecmp.c: Likewise. + * copy-file.c: Update from gnulib. * atexit.c: Update from gnulib. diff --git a/gettext-tools/lib/c-strcasecmp.c b/gettext-tools/lib/c-strcasecmp.c index 2e3012e4d..00e302594 100644 --- a/gettext-tools/lib/c-strcasecmp.c +++ b/gettext-tools/lib/c-strcasecmp.c @@ -22,6 +22,8 @@ /* Specification. */ #include "c-strcase.h" +#include + #include "c-ctype.h" int @@ -47,5 +49,11 @@ c_strcasecmp (const char *s1, const char *s2) } while (c1 == c2); - return c1 - c2; + if (UCHAR_MAX <= INT_MAX) + return c1 - c2; + else + /* On machines where 'char' and 'int' are types of the same size, the + difference of two 'unsigned char' values - including the sign bit - + doesn't fit in an 'int'. */ + return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0); } diff --git a/gettext-tools/lib/c-strncasecmp.c b/gettext-tools/lib/c-strncasecmp.c index 33e8091b7..2d260efb6 100644 --- a/gettext-tools/lib/c-strncasecmp.c +++ b/gettext-tools/lib/c-strncasecmp.c @@ -22,6 +22,8 @@ /* Specification. */ #include "c-strcase.h" +#include + #include "c-ctype.h" int @@ -47,5 +49,11 @@ c_strncasecmp (const char *s1, const char *s2, size_t n) } while (c1 == c2); - return c1 - c2; + if (UCHAR_MAX <= INT_MAX) + return c1 - c2; + else + /* On machines where 'char' and 'int' are types of the same size, the + difference of two 'unsigned char' values - including the sign bit - + doesn't fit in an 'int'. */ + return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0); }