From 68067e4e501e2ae1c0fb44558b6aa5c0a80a4143 Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Fri, 29 Nov 2013 17:44:12 +0000 Subject: [PATCH] fix -Wsign-compare in core There were a few places that were doing unsigned_var = cond ? signed_val : unsigned_val; or similar. Fixed by suitable casts etc. The four in utf8.c were fixed by assigning to an intermediate unsigned var; this has the happy side-effect of collapsing a large macro expansion, where toUPPER_LC() etc evaluate their arg multiple times. --- handy.h | 4 ++-- locale.c | 4 ++-- utf8.c | 12 ++++++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/handy.h b/handy.h index 2ea7a6e..b63fa59 100644 --- a/handy.h +++ b/handy.h @@ -1197,8 +1197,8 @@ EXTCONST U32 PL_charclass[]; #define toUPPER(c) (isASCII(c) ? toUPPER_LATIN1_MOD(c) : (c)) which uses table lookup and mask instead of subtraction. (This would work because the _MOD does not apply in the ASCII range) */ -#define toLOWER(c) (isUPPER(c) ? (c) + ('a' - 'A') : (c)) -#define toUPPER(c) (isLOWER(c) ? (c) - ('a' - 'A') : (c)) +#define toLOWER(c) (isUPPER(c) ? (U8)((c) + ('a' - 'A')) : (c)) +#define toUPPER(c) (isLOWER(c) ? (U8)((c) - ('a' - 'A')) : (c)) /* In the ASCII range, these are equivalent to what they're here defined to be. * But by creating these definitions, other code doesn't have to be aware of diff --git a/locale.c b/locale.c index 7ec3463..6284199 100644 --- a/locale.c +++ b/locale.c @@ -186,11 +186,11 @@ Perl_new_ctype(pTHX_ const char *newctype) { #ifdef USE_LOCALE_CTYPE dVAR; - int i; + UV i; PERL_ARGS_ASSERT_NEW_CTYPE; - for (i = 0; i < 256; i++) { + for (i = 0; i ; i++) { if (isUPPER_LC(i)) PL_fold_locale[i] = toLOWER_LC(i); else if (isLOWER_LC(i)) diff --git a/utf8.c b/utf8.c index bf51a91..debe0e9 100644 --- a/utf8.c +++ b/utf8.c @@ -2587,7 +2587,8 @@ Perl__to_utf8_upper_flags(pTHX_ const U8 *p, U8* ustrp, STRLEN *lenp, const bool } else if UTF8_IS_DOWNGRADEABLE_START(*p) { if (flags) { - result = toUPPER_LC(TWO_BYTE_UTF8_TO_NATIVE(*p, *(p+1))); + UV c = TWO_BYTE_UTF8_TO_NATIVE(*p, *(p+1)); + result = toUPPER_LC(c); } else { return _to_upper_title_latin1(TWO_BYTE_UTF8_TO_NATIVE(*p, *(p+1)), @@ -2653,7 +2654,8 @@ Perl__to_utf8_title_flags(pTHX_ const U8 *p, U8* ustrp, STRLEN *lenp, const bool } else if UTF8_IS_DOWNGRADEABLE_START(*p) { if (flags) { - result = toUPPER_LC(TWO_BYTE_UTF8_TO_NATIVE(*p, *(p+1))); + UV c = TWO_BYTE_UTF8_TO_NATIVE(*p, *(p+1)); + result = toUPPER_LC(c); } else { return _to_upper_title_latin1(TWO_BYTE_UTF8_TO_NATIVE(*p, *(p+1)), @@ -2717,7 +2719,8 @@ Perl__to_utf8_lower_flags(pTHX_ const U8 *p, U8* ustrp, STRLEN *lenp, const bool } else if UTF8_IS_DOWNGRADEABLE_START(*p) { if (flags) { - result = toLOWER_LC(TWO_BYTE_UTF8_TO_NATIVE(*p, *(p+1))); + UV c = TWO_BYTE_UTF8_TO_NATIVE(*p, *(p+1)); + result = toLOWER_LC(c); } else { return to_lower_latin1(TWO_BYTE_UTF8_TO_NATIVE(*p, *(p+1)), @@ -2795,7 +2798,8 @@ Perl__to_utf8_fold_flags(pTHX_ const U8 *p, U8* ustrp, STRLEN *lenp, U8 flags, b } else if UTF8_IS_DOWNGRADEABLE_START(*p) { if (flags & FOLD_FLAGS_LOCALE) { - result = toFOLD_LC(TWO_BYTE_UTF8_TO_NATIVE(*p, *(p+1))); + UV c = TWO_BYTE_UTF8_TO_NATIVE(*p, *(p+1)); + result = toFOLD_LC(c); } else { return _to_fold_latin1(TWO_BYTE_UTF8_TO_NATIVE(*p, *(p+1)), -- 2.7.4