diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-07-02 18:50:25 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-07-25 16:14:45 +0200 |
commit | 8cbc92d5975b603002c3141364a7709a9c66e23a (patch) | |
tree | 9feb74f8ed02c860e40d223f504ce321d3e66558 /src/basic/parse-util.c | |
parent | man: document CPUAffinity= in system.conf in more detail (diff) | |
download | systemd-8cbc92d5975b603002c3141364a7709a9c66e23a.tar.xz systemd-8cbc92d5975b603002c3141364a7709a9c66e23a.zip |
parse-util: in parse_permille() check negative earlier
If 'v' is negative, it's wrong to add the decimal to it, as we'd
actually need to subtract it in this case. But given that we don't want
to allow negative vaues anyway, simply check earlier whether what we
have parsed so far was negative, and react to that before adding the
decimal to it.
Diffstat (limited to 'src/basic/parse-util.c')
-rw-r--r-- | src/basic/parse-util.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c index 6becf85878..db38f91c83 100644 --- a/src/basic/parse-util.c +++ b/src/basic/parse-util.c @@ -637,6 +637,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) @@ -657,15 +659,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; } |