Future<Unit> global fixup
[folly.git] / folly / Conv.cpp
index 57b1aeef718e2d0d00ccc87e43c92e791f9ba5f8..0ae9b2222d6ba80164d6f37397f03b01866c850d 100644 (file)
@@ -81,14 +81,13 @@ bool str_to_bool(StringPiece* src) {
   switch (*b) {
     case '0':
     case '1': {
-      // Attempt to parse the value as an integer
-      StringPiece tmp(*src);
-      uint8_t value = to<uint8_t>(&tmp);
-      // Only accept 0 or 1
-      FOLLY_RANGE_CHECK_STRINGPIECE(
-        value <= 1, "Integer overflow when parsing bool: must be 0 or 1", *src);
-      b = tmp.begin();
-      result = (value == 1);
+      result = false;
+      for (; b < e && isdigit(*b); ++b) {
+        FOLLY_RANGE_CHECK_STRINGPIECE(
+          !result && (*b == '0' || *b == '1'),
+          "Integer overflow when parsing bool: must be 0 or 1", *src);
+        result = (*b == '1');
+      }
       break;
     }
     case 'y':