On 11/21/2013 03:20 PM, Antonio Quartulli wrote:
On Thu, Nov 21, 2013 at 02:57:50PM +0100, Matthias Schiffer wrote:
On 11/21/2013 08:21 AM, Antonio Quartulli wrote:
On Thu, Nov 21, 2013 at 04:45:14AM +0100, Matthias Schiffer wrote:
You are casting a u32 * to unsigned long *? Won't this break horribly when sizeof(u32) != sizeof(unsigned long)?
It will break when sizeof(unsigned long) > sizeof(uint32). For example on x86_64. Hopefully nobody would use such ancient kernel on his machine. But you are right.
What do you think of the attached patch?
That's better, but if you care about overflow, you should add something like
if (_v != (unsigned long)v) _r = -ERANGE;
yeah, thanks! I'll add this!
Also, the comment in the line above doesn't make sense anymore...
yeah, I removed that already.
Ah, and I overlooked that you have to dereference v and take the address of _v; adding parantheses around the parameters might also be a good idea as it is a macro.
So I'd recommend something like this (not even compile tested...):
({\ unsigned long _v;\ int _r;\ _r = strict_strtoul((cp), (base), &_v);\ if (_v == (unsigned long)(u32)_v)\ *(v) = (u32)_v;\ else\ _r = -ERANGE;\ _r;\ })