summaryrefslogtreecommitdiffstats
path: root/contrib/ntp/libntp/hextoint.c
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2015-07-15 19:21:26 +0000
committerdelphij <delphij@FreeBSD.org>2015-07-15 19:21:26 +0000
commit2a25cee78ab1d37e7d2bc40ae675646974d99f56 (patch)
treeb0302ac4be59e104f4e1e54014561a1389397192 /contrib/ntp/libntp/hextoint.c
parenta0741a75537b2e0514472ac3b28afc55a7846c30 (diff)
downloadFreeBSD-src-2a25cee78ab1d37e7d2bc40ae675646974d99f56.zip
FreeBSD-src-2a25cee78ab1d37e7d2bc40ae675646974d99f56.tar.gz
MFC r280849,280915-280916,281015-281016,282097,282408,282415,283542,
284864,285169-285170,285435: ntp 4.2.8p3. Relnotes: yes Approved by: re (?)
Diffstat (limited to 'contrib/ntp/libntp/hextoint.c')
-rw-r--r--contrib/ntp/libntp/hextoint.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/contrib/ntp/libntp/hextoint.c b/contrib/ntp/libntp/hextoint.c
index 0d774eb..980a43f 100644
--- a/contrib/ntp/libntp/hextoint.c
+++ b/contrib/ntp/libntp/hextoint.c
@@ -2,6 +2,7 @@
* hextoint - convert an ascii string in hex to an unsigned
* long, with error checking
*/
+#include <config.h>
#include <ctype.h>
#include "ntp_stdlib.h"
@@ -9,7 +10,7 @@
int
hextoint(
const char *str,
- u_long *ival
+ u_long *pu
)
{
register u_long u;
@@ -18,22 +19,24 @@ hextoint(
cp = str;
if (*cp == '\0')
- return 0;
+ return 0;
u = 0;
while (*cp != '\0') {
- if (!isxdigit((int)*cp))
- return 0;
- if (u >= 0x10000000)
- return 0; /* overflow */
+ if (!isxdigit((unsigned char)*cp))
+ return 0;
+ if (u & 0xF0000000)
+ return 0; /* overflow */
u <<= 4;
- if (*cp <= '9') /* very ascii dependent */
- u += *cp++ - '0';
- else if (*cp >= 'a')
- u += *cp++ - 'a' + 10;
+ if ('0' <= *cp && *cp <= '9')
+ u += *cp++ - '0';
+ else if ('a' <= *cp && *cp <= 'f')
+ u += *cp++ - 'a' + 10;
+ else if ('A' <= *cp && *cp <= 'F')
+ u += *cp++ - 'A' + 10;
else
- u += *cp++ - 'A' + 10;
+ return 0;
}
- *ival = u;
+ *pu = u;
return 1;
}
OpenPOWER on IntegriCloud