From 5bbd0819e6ca208dc500ad3f2ae898ec188fff59 Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Tue, 11 Aug 2015 18:52:41 +0100 Subject: [PATCH] More accurate loop counting (inspired by [-Wsign-compare]). --- re2c/src/ir/regexp/encoding/utf8/utf8_range.cc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/re2c/src/ir/regexp/encoding/utf8/utf8_range.cc b/re2c/src/ir/regexp/encoding/utf8/utf8_range.cc index 147a5573..c81e12c3 100644 --- a/re2c/src/ir/regexp/encoding/utf8/utf8_range.cc +++ b/re2c/src/ir/regexp/encoding/utf8/utf8_range.cc @@ -9,23 +9,25 @@ namespace re2c { */ void UTF8addContinuous(RangeSuffix * & root, utf8::rune l, utf8::rune h, uint32_t n) { - uint32_t cl[utf8::MAX_RUNE_LENGTH]; - uint32_t ch[utf8::MAX_RUNE_LENGTH]; - utf8::rune_to_bytes(cl, l); - utf8::rune_to_bytes(ch, h); + uint32_t lcs[utf8::MAX_RUNE_LENGTH]; + uint32_t hcs[utf8::MAX_RUNE_LENGTH]; + utf8::rune_to_bytes(lcs, l); + utf8::rune_to_bytes(hcs, h); RangeSuffix ** p = &root; - for (int i = n - 1; i >= 0; --i) + for (uint32_t i = 1; i <= n; ++i) { + const uint32_t lc = lcs[n - i]; + const uint32_t hc = hcs[n - i]; for (;;) { if (*p == NULL) { - *p = new RangeSuffix(cl[i], ch[i]); + *p = new RangeSuffix(lc, hc); p = &(*p)->child; break; } - else if ((*p)->l == cl[i] && (*p)->h == ch[i]) + else if ((*p)->l == lc && (*p)->h == hc) { p = &(*p)->child; break; @@ -66,7 +68,7 @@ void UTF8splitByContinuity(RangeSuffix * & root, utf8::rune l, utf8::rune h, uin { for (uint32_t i = 1; i < n; ++i) { - uint32_t m = (1 << (6 * i)) - 1; // last i bytes of a UTF-8 sequence + uint32_t m = (1u << (6u * i)) - 1u; // last i bytes of a UTF-8 sequence if ((l & ~m) != (h & ~m)) { if ((l & m) != 0) -- 2.40.0