diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c index 992ea3605b..2ab8e88451 100644 --- a/src/basic/parse-util.c +++ b/src/basic/parse-util.c @@ -728,6 +728,8 @@ int parse_permille_unbounded(const char *p) { r = safe_atoi(n, &v); if (r < 0) return r; + if (v < 0) + return -ERANGE; } else { pc = endswith(p, "%"); if (!pc) @@ -748,15 +750,14 @@ int parse_permille_unbounded(const char *p) { r = safe_atoi(n, &v); if (r < 0) return r; + if (v < 0) + return -ERANGE; if (v > (INT_MAX - q) / 10) return -ERANGE; v = v * 10 + q; } - if (v < 0) - return -ERANGE; - return v; }