Simplify getulong

Use strtoul to read an unsigned long, rather than reading
a signed long long and casting it.

https://bugzilla.suse.com/show_bug.cgi?id=979282
This commit is contained in:
Sebastian Krahmer 2016-08-03 11:51:07 -05:00 committed by Serge Hallyn
parent 7f5a14817d
commit 1d5a926cc2

View File

@ -44,22 +44,19 @@
*/ */
int getulong (const char *numstr, /*@out@*/unsigned long int *result) int getulong (const char *numstr, /*@out@*/unsigned long int *result)
{ {
long long int val; unsigned long int val;
char *endptr; char *endptr;
errno = 0; errno = 0;
val = strtoll (numstr, &endptr, 0); val = strtoul (numstr, &endptr, 0);
if ( ('\0' == *numstr) if ( ('\0' == *numstr)
|| ('\0' != *endptr) || ('\0' != *endptr)
|| (ERANGE == errno) || (ERANGE == errno)
/*@+ignoresigns@*/
|| (val != (unsigned long int)val)
/*@=ignoresigns@*/
) { ) {
return 0; return 0;
} }
*result = (unsigned long int)val; *result = val;
return 1; return 1;
} }