[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20111125092451.19e0e9d4@nehalam.linuxnetplumber.net>
Date: Fri, 25 Nov 2011 09:24:51 -0800
From: Stephen Hemminger <shemminger@...tta.com>
To: "David Laight" <David.Laight@...LAB.COM>
Cc: "Hagen Paul Pfeifer" <hagen@...u.net>, <netdev@...r.kernel.org>
Subject: Re: [PATCH iproute2 1/2] utils: add s32 parser
On Fri, 25 Nov 2011 09:46:09 -0000
"David Laight" <David.Laight@...LAB.COM> wrote:
> > + res = strtoul(arg, &ptr, base);
> > + if (!ptr || ptr == arg || *ptr || res > INT32_MAX || res <
> INT32_MIN)
>
> No need to check !ptr.
Also don't you want signed value? Reading strtol() man page,
the correct way is:
errno = 0;
res = strtol(arg, &ptr, base);
if (ptr == arg || errno)
return -1;
"RETURN VALUE
The strtol() function returns the result of the conversion, unless the
value would underflow or overflow. If an underflow occurs, strtol()
returns LONG_MIN. If an overflow occurs, strtol() returns LONG_MAX.
In both cases, errno is set to ERANGE. Precisely the same holds for
strtoll() (with LLONG_MIN and LLONG_MAX instead of LONG_MIN and
LONG_MAX).
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists