>From 09af21003026a61e6f1d51f0a2d6d71f04834a78 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 5 Sep 2020 15:44:29 +0200 Subject: [PATCH 2/3] uniname/uniname: Fix -Wshorten-64-to-32 warnings. * lib/uniname/uniname.c (unicode_name_word_lookup): Change type of last argument to size_t. (unicode_name_character): Change type of len, n1, n2, n3, words_length, n to size_t. --- ChangeLog | 8 ++++++++ lib/uniname/uniname.c | 23 +++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0d50b68..205d98a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2020-09-05 Bruno Haible + uniname/uniname: Fix -Wshorten-64-to-32 warnings. + * lib/uniname/uniname.c (unicode_name_word_lookup): Change type of last + argument to size_t. + (unicode_name_character): Change type of len, n1, n2, n3, words_length, + n to size_t. + +2020-09-05 Bruno Haible + unistr/u{8,16,32}-uctomb: Avoid possible trouble with huge strings. * lib/unistr.in.h (u8_uctomb_aux, u8_uctomb, u16_uctomb_aux, u16_uctomb, u32_uctomb): Change type of last argument to ptrdiff_t. diff --git a/lib/uniname/uniname.c b/lib/uniname/uniname.c index 7cf1e2e..db8399d 100644 --- a/lib/uniname/uniname.c +++ b/lib/uniname/uniname.c @@ -90,7 +90,7 @@ unicode_name_word (unsigned int index, unsigned int *lengthp) /* Looks up the index of a word. */ static int -unicode_name_word_lookup (const char *word, unsigned int length) +unicode_name_word_lookup (const char *word, size_t length) { if (length > 0 && length < SIZEOF (unicode_name_by_length) - 1) { @@ -359,7 +359,7 @@ unicode_character_name (ucs4_t c, char *buf) ucs4_t unicode_name_character (const char *name) { - unsigned int len = strlen (name); + size_t len = strlen (name); if (len > 1 && len <= UNICODE_CHARNAME_MAX_LENGTH) { /* Test for "word1 word2 ..." syntax. */ @@ -469,9 +469,9 @@ unicode_name_character (const char *name) p4++; if (p4 == ptr) { - unsigned int n1 = p2 - p1; - unsigned int n2 = p3 - p2; - unsigned int n3 = p4 - p3; + size_t n1 = p2 - p1; + size_t n2 = p3 - p2; + size_t n3 = p4 - p3; if (n1 <= 2 && (n2 >= 1 && n2 <= 3) && n3 <= 2) { @@ -578,12 +578,15 @@ unicode_name_character (const char *name) filled_words: { /* Multiply by 2, to simplify later comparisons. */ - unsigned int words_length = wordptr - words; + size_t words_length = wordptr - words; { - int i = words_length - 1; + size_t i = words_length - 1; words[i] = 2 * words[i]; - for (; --i >= 0; ) - words[i] = 2 * words[i] + 1; + for (; i > 0; ) + { + --i; + words[i] = 2 * words[i] + 1; + } } /* Binary search in unicode_name_to_index. */ { @@ -594,7 +597,7 @@ unicode_name_character (const char *name) unsigned int i = (i1 + i2) >> 1; const uint16_t *w = words; const uint16_t *p = &unicode_names[unicode_name_to_index[i].name]; - unsigned int n = words_length; + size_t n = words_length; for (;;) { if (*p < *w) -- 2.7.4