Fix some implicit truncations in the interaction with OpenSSL APIs
[folly.git] / folly / Conv.cpp
index 0ab6dcf50470bd1108714160b4cf7a528beba6dc..3e5214a879fa775ebcc424ea66a1332e9a1642f8 100644 (file)
@@ -549,7 +549,7 @@ inline Expected<Tgt, ConversionCode> digits_to(
   UT result = 0;
 
   for (; e - b >= 4; b += 4) {
-    result *= 10000;
+    result *= static_cast<UT>(10000);
     const int32_t r0 = shift1000[static_cast<size_t>(b[0])];
     const int32_t r1 = shift100[static_cast<size_t>(b[1])];
     const int32_t r2 = shift10[static_cast<size_t>(b[2])];
@@ -558,7 +558,7 @@ inline Expected<Tgt, ConversionCode> digits_to(
     if (sum >= OOR) {
       goto outOfRange;
     }
-    result += sum;
+    result += UT(sum);
   }
 
   switch (e - b) {
@@ -631,7 +631,7 @@ template Expected<unsigned int, ConversionCode> digits_to<unsigned int>(
 
 template Expected<long, ConversionCode> digits_to<long>(
     const char*,
-    const char*);
+    const char*) noexcept;
 template Expected<unsigned long, ConversionCode> digits_to<unsigned long>(
     const char*,
     const char*) noexcept;