Message ID | 20240530082007.1427631-2-dominique.martinet@atmark-techno.com |
---|---|
State | Accepted |
Headers | show |
Series | downloader curl options: add max-download-speed | expand |
On 30.05.24 10:20, Dominique Martinet wrote: > ustrtoull would check suffixes for k/K/M/G, but just ignore anything else: > - handle m/g as well (why k but not others?) > - clearly error if unrecognized suffix is used > > Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com> > --- > v2->v3: remove error message > > core/util.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/core/util.c b/core/util.c > index 84df7ad09388..70f0d28f6d61 100644 > --- a/core/util.c > +++ b/core/util.c > @@ -721,9 +721,11 @@ unsigned long long ustrtoull(const char *cp, char **endptr, unsigned int base) > > switch (*endp) { > case 'G': > + case 'g': > result *= 1024; > /* fall through */ > case 'M': > + case 'm': > result *= 1024; > /* fall through */ > case 'K': > @@ -737,6 +739,12 @@ unsigned long long ustrtoull(const char *cp, char **endptr, unsigned int base) > } else { > endp += 1; > } > + case 0: > + break; > + default: > + errno = EINVAL; > + result = 0; > + goto out; > } > > out: Acked-by: Stefano Babic <stefano.babic@swupdate.org>
diff --git a/core/util.c b/core/util.c index 84df7ad09388..70f0d28f6d61 100644 --- a/core/util.c +++ b/core/util.c @@ -721,9 +721,11 @@ unsigned long long ustrtoull(const char *cp, char **endptr, unsigned int base) switch (*endp) { case 'G': + case 'g': result *= 1024; /* fall through */ case 'M': + case 'm': result *= 1024; /* fall through */ case 'K': @@ -737,6 +739,12 @@ unsigned long long ustrtoull(const char *cp, char **endptr, unsigned int base) } else { endp += 1; } + case 0: + break; + default: + errno = EINVAL; + result = 0; + goto out; } out:
ustrtoull would check suffixes for k/K/M/G, but just ignore anything else: - handle m/g as well (why k but not others?) - clearly error if unrecognized suffix is used Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com> --- v2->v3: remove error message core/util.c | 8 ++++++++ 1 file changed, 8 insertions(+)