diff options
Diffstat (limited to 'contrib/bind9/lib/isc/parseint.c')
-rw-r--r-- | contrib/bind9/lib/isc/parseint.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/contrib/bind9/lib/isc/parseint.c b/contrib/bind9/lib/isc/parseint.c index 266d44c..f8ec389 100644 --- a/contrib/bind9/lib/isc/parseint.c +++ b/contrib/bind9/lib/isc/parseint.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004, 2005, 2007, 2012 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 2001-2003 Internet Software Consortium. * * Permission to use, copy, modify, and/or distribute this software for any @@ -32,6 +32,7 @@ isc_result_t isc_parse_uint32(isc_uint32_t *uip, const char *string, int base) { unsigned long n; + isc_uint32_t r; char *e; if (! isalnum((unsigned char)(string[0]))) return (ISC_R_BADNUMBER); @@ -39,9 +40,15 @@ isc_parse_uint32(isc_uint32_t *uip, const char *string, int base) { n = strtoul(string, &e, base); if (*e != '\0') return (ISC_R_BADNUMBER); - if (n == ULONG_MAX && errno == ERANGE) + /* + * Where long is 64 bits we need to convert to 32 bits then test for + * equality. This is a no-op on 32 bit machines and a good compiler + * will optimise it away. + */ + r = (isc_uint32_t)n; + if ((n == ULONG_MAX && errno == ERANGE) || (n != (unsigned long)r)) return (ISC_R_RANGE); - *uip = n; + *uip = r; return (ISC_R_SUCCESS); } |