From a5e7ffb0d97020a38389e5524ce8f3a03ddd86bd Mon Sep 17 00:00:00 2001 From: Shane Carr <shane@unicode.org> Date: Sat, 17 Jun 2017 00:48:17 +0000 Subject: [PATCH] ICU-13246 Changing util64_pow to work on uint64_t to fix signed integer overflow warning in Clang X-SVN-Rev: 40174 --- icu4c/source/i18n/nfrs.cpp | 7 +++---- icu4c/source/i18n/nfrs.h | 5 +++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/icu4c/source/i18n/nfrs.cpp b/icu4c/source/i18n/nfrs.cpp index 05941e8b293..74ce27a401a 100644 --- a/icu4c/source/i18n/nfrs.cpp +++ b/icu4c/source/i18n/nfrs.cpp @@ -830,12 +830,12 @@ int64_t util64_fromDouble(double d) { return result; } -int64_t util64_pow(int32_t base, uint16_t exponent) { +uint64_t util64_pow(uint32_t base, uint16_t exponent) { if (base == 0) { return 0; } - int64_t result = 1; - int64_t pow = base; + uint64_t result = 1; + uint64_t pow = base; while (exponent > 0) { if ((exponent & 1) == 1) { result *= pow; @@ -1027,4 +1027,3 @@ U_NAMESPACE_END /* U_HAVE_RBNF */ #endif - diff --git a/icu4c/source/i18n/nfrs.h b/icu4c/source/i18n/nfrs.h index d28c29c1be3..1e39b289b4d 100644 --- a/icu4c/source/i18n/nfrs.h +++ b/icu4c/source/i18n/nfrs.h @@ -88,7 +88,9 @@ private: int64_t util64_fromDouble(double d); // raise radix to the power exponent, only non-negative exponents -int64_t util64_pow(int32_t radix, uint16_t exponent); +// Arithmetic is performed in unsigned space since overflow in +// signed space is undefined behavior. +uint64_t util64_pow(uint32_t radix, uint16_t exponent); // convert n to digit string in buffer, return length of string uint32_t util64_tou(int64_t n, UChar* buffer, uint32_t buflen, uint32_t radix = 10, UBool raw = FALSE); @@ -107,4 +109,3 @@ U_NAMESPACE_END // NFRS_H #endif - -- 2.40.0