lkml.org 
[lkml]   [2018]   [Oct]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/2] sysctl: add overflow detection to proc_get_long()
On Sun, Oct 14, 2018 at 03:25:09PM +0200, Christian Brauner wrote:

> +static unsigned long sysctl_strtoul_lenient(const char *cp, char **endp,
> + unsigned int base, bool *overflow)
> +{
> + unsigned long long result;
> + unsigned int rv;
> +
> + cp = _parse_integer_fixup_radix(cp, &base);
> + rv = _parse_integer(cp, base, &result);
> + if ((rv & KSTRTOX_OVERFLOW) ||
> + (result != (unsigned long long)(unsigned long)result))
> + *overflow = true;
> + else
> + *overflow = false;

Yecchh... First of all, the cast back to unsigned long long is completely
pointless. What's more,
if (expr)
foo = true;
else
foo = flase;
is a fairly unidiomatic way to spell foo = expr;

And... is there anything that would really care if this "overflow" thing had
been replaced by simply returning ~0UL on such? That would appear to be
a lot more natural API...

\
 
 \ /
  Last update: 2018-10-14 19:19    [W:0.058 / U:1.104 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site