Re: [PATCH iproute2 1/2] utils: add s32 parser

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

On Fri, 25 Nov 2011 09:46:09 -0000
"David Laight" <David.Laight@xxxxxxxxxx> 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@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Linux Kernel Discussion]     [Ethernet Bridging]     [Linux Wireless Networking]     [Linux Bluetooth Networking]     [Linux Networking Users]     [VLAN]     [Git]     [IETF Annouce]     [Linux Assembly]     [Security]     [Bugtraq]     [Photo]     [Singles Social Networking]     [Yosemite Information]     [MIPS Linux]     [ARM Linux Kernel]     [ARM Linux]     [Linux Virtualization]     [Linux Security]     [Linux IDE]     [Linux RAID]     [Linux SCSI]     [Free Dating]

Add to Google Powered by Linux