[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20181015000310.GX32577@ZenIV.linux.org.uk>
Date: Mon, 15 Oct 2018 01:03:10 +0100
From: Al Viro <viro@...IV.linux.org.uk>
To: Christian Brauner <christian@...uner.io>
Cc: keescook@...omium.org, linux-kernel@...r.kernel.org,
ebiederm@...ssion.com, mcgrof@...nel.org,
akpm@...ux-foundation.org, joe.lawrence@...hat.com,
longman@...hat.com
Subject: Re: [PATCH 1/2] sysctl: add overflow detection to proc_get_long()
On Sun, Oct 14, 2018 at 08:53:46PM +0200, Christian Brauner wrote:
> > Yecchh... First of all, the cast back to unsigned long long is completely
> > pointless. What's more,
>
> Sorry, seriously asking: why? This was meant to handle the case where
> sizeof(unsigned long long) != sizeof(unsigned long) and I just looked at
> _kstrtoul() which does the same:
>
> int _kstrtoul(const char *s, unsigned int base, unsigned long *res)
> {
> unsigned long long tmp;
> int rv;
>
> rv = kstrtoull(s, base, &tmp);
> if (rv < 0)
> return rv;
> if (tmp != (unsigned long long)(unsigned long)tmp)
> return -ERANGE;
> *res = tmp;
> return 0;
> }
>
> Sorry, if I'm being dense here.
C quiz:
given that type of e1 is unsigned long long and type of e2 -
unsigned long, what conversions are going to happen in e1 == e2?
[relevant part of C standard: 6.5.9 (Equality operators),
6.3.1.8 (Usual arithmetic conversions)]
Powered by blists - more mailing lists