options/internal: Fix off-by-one in strtofp and simplify
@@ -17,36 +17,32 @@ T strtofp(const char *str, char **endptr) {
T result = static_cast<T>(0);
- const char *dot = strchr(str, '.');
- const char *end = str + strlen(str) - 1;
- const char *dot_end = dot ?: (end + 1);
const char *tmp = str;
- while (tmp < dot_end) {
+ while (true) {
if (!isdigit(*tmp))
- goto ret;
+ break;
result *= static_cast<T>(10);
result += static_cast<T>(*tmp - '0');
tmp++;
}
- if (dot) {
+ if (*tmp == '.') {
T d = static_cast<T>(10);
- tmp = dot;
if (*(tmp + 1) == '0' && (*(tmp + 2) == 'x' || *(tmp + 2) == 'X'))
__ensure(!"hex numbers in strtofp are unsupported");
-
- while (tmp < end) {
tmp++;
+
+ while (true) {
if (!isdigit(*tmp))
- goto ret;
+ break;
result += static_cast<T>(*tmp - '0') / d;
d *= static_cast<T>(10);
+ tmp++;
}
}
-ret:
if (endptr)
*endptr = const_cast<char *>(tmp);
if (negative)
