summaryrefslogtreecommitdiff
path: root/strtoaddr.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2019-09-01 16:11:32 -0700
committerGuy Harris <guy@alum.mit.edu>2019-09-01 16:11:32 -0700
commit9a6a6502413e657277e74ac1d0842ddca34cab50 (patch)
tree09d3a2d474389be1d655f92a19263b713dd8677e /strtoaddr.c
parent50c1904960bec90e234100a7c1b081d771c48e9b (diff)
downloadtcpdump-9a6a6502413e657277e74ac1d0842ddca34cab50.tar.gz
Don't use <ctype.h> macros.
Some of them are locale-dependent, and all of them run the risk of failing if you hand them a char with the 8th bit set. Move our replacements to a new netdissect-ctype.h file, and, for the ones that check for particular character types, add _ASCII to the name, to indicate that only ASCII characters pass the check. Do the same for the ones that map between cases, to indicate that they only map ASCII letters. For isspace(), explicitly check for the characters we care about, to make it clearer what we're doing.
Diffstat (limited to 'strtoaddr.c')
-rw-r--r--strtoaddr.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/strtoaddr.c b/strtoaddr.c
index e38a9d4e..b3b84972 100644
--- a/strtoaddr.c
+++ b/strtoaddr.c
@@ -23,6 +23,8 @@
#include <stddef.h>
#include <string.h>
+#include "netdissect-ctype.h"
+
#include "strtoaddr.h"
#ifndef NS_INADDRSZ
@@ -69,18 +71,18 @@ strtoaddr(const char *src, void *dst)
* Values are specified as for C:
* 0x=hex, 0=octal, isdigit=decimal.
*/
- if (!isdigit(c))
+ if (!ND_ASCII_ISDIGIT(c))
return (0);
val = 0;
if (c == '0') {
c = *++src;
if (c == 'x' || c == 'X')
return (0);
- else if (isdigit(c) && c != '9')
+ else if (ND_ASCII_ISDIGIT(c) && c != '9')
return (0);
}
for (;;) {
- if (isdigit(c)) {
+ if (ND_ASCII_ISDIGIT(c)) {
digit = c - '0';
if (digit >= 10)
break;
@@ -107,7 +109,7 @@ strtoaddr(const char *src, void *dst)
/*
* Check for trailing characters.
*/
- if (c != '\0' && !isspace(c))
+ if (c != '\0' && c != ' ' && c != '\t')
return (0);
/*
* Find the number of parts specified.