diff options
author | Erwin Lansing <erwin@FreeBSD.org> | 2013-07-24 07:12:55 +0000 |
---|---|---|
committer | Erwin Lansing <erwin@FreeBSD.org> | 2013-07-24 07:12:55 +0000 |
commit | 6f34f6a389ca8199c4b20c17f62d7d924baef7fb (patch) | |
tree | e392027bf54f7a1fd2a6f3a16ecb4487844b44e9 /lib/isc/parseint.c | |
parent | 650b026006ec14e630f658a0f877099ec38b660b (diff) |
Notes
Diffstat (limited to 'lib/isc/parseint.c')
-rw-r--r-- | lib/isc/parseint.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/isc/parseint.c b/lib/isc/parseint.c index 266d44cec5c5..f8ec3892c2c5 100644 --- a/lib/isc/parseint.c +++ b/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); } |