util-lib: add parse_percent_unbounded() for percentages over 100% (#3886)
This permits CPUQuota to accept greater values as documented.
This commit is contained in:
committed by
Lennart Poettering
parent
19c8201744
commit
5124866d73
+10
-3
@@ -533,7 +533,7 @@ int parse_fractional_part_u(const char **p, size_t digits, unsigned *res) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parse_percent(const char *p) {
|
||||
int parse_percent_unbounded(const char *p) {
|
||||
const char *pc, *n;
|
||||
unsigned v;
|
||||
int r;
|
||||
@@ -546,8 +546,15 @@ int parse_percent(const char *p) {
|
||||
r = safe_atou(n, &v);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (v > 100)
|
||||
return -ERANGE;
|
||||
|
||||
return (int) v;
|
||||
}
|
||||
|
||||
int parse_percent(const char *p) {
|
||||
int v = parse_percent_unbounded(p);
|
||||
|
||||
if (v > 100)
|
||||
return -ERANGE;
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user