]> granicus.if.org Git - icu/commitdiff
ICU-13550 decNumber int overflow, switch to unsigned to avoid undefined behavior.
authorAndy Heninger <andy.heninger@gmail.com>
Mon, 19 Feb 2018 03:13:08 +0000 (03:13 +0000)
committerAndy Heninger <andy.heninger@gmail.com>
Mon, 19 Feb 2018 03:13:08 +0000 (03:13 +0000)
X-SVN-Rev: 40950

icu4c/source/i18n/decNumber.cpp

index 149062e09213aaa4291af231626b6515ecef5fb7..cee2f8e94984030bad4562d427eb8be1c3ff6eb6 100644 (file)
@@ -627,10 +627,12 @@ U_CAPI decNumber * U_EXPORT2 uprv_decNumberFromString(decNumber *dn, const char
 
       for (; *c=='0' && *(c+1)!='\0';) c++;  /* strip insignificant zeros  */
       firstexp=c;                            /* save exponent digit place  */
+      uInt uexponent = 0;   /* Avoid undefined behavior on signed int overflow */
       for (; ;c++) {
         if (*c<'0' || *c>'9') break;         /* not a digit  */
-        exponent=X10(exponent)+(Int)*c-(Int)'0';
+        uexponent=X10(uexponent)+(uInt)*c-(uInt)'0';
         } /* c  */
+      exponent = (Int)uexponent;
       /* if not now on a '\0', *c must not be a digit  */
       if (*c!='\0') break;