aboutsummaryrefslogtreecommitdiffstats
path: root/node.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2016-06-15 21:50:45 +0300
committerArnold D. Robbins <arnold@skeeve.com>2016-06-15 21:50:45 +0300
commitf4bbf63a287cd73f4eb989539e4813a428bf05ad (patch)
tree313b4a799a7b58b6bfedbee30be9d0419c748aed /node.c
parent5826beec258141776469c5fd9b703d52c81a35fb (diff)
parentddb62efafb5659dae532089af83350f066446424 (diff)
downloadegawk-f4bbf63a287cd73f4eb989539e4813a428bf05ad.tar.gz
egawk-f4bbf63a287cd73f4eb989539e4813a428bf05ad.tar.bz2
egawk-f4bbf63a287cd73f4eb989539e4813a428bf05ad.zip
Merge branch 'master' into feature/fixtype
Diffstat (limited to 'node.c')
-rw-r--r--node.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/node.c b/node.c
index 7bc48cb9..89d889a4 100644
--- a/node.c
+++ b/node.c
@@ -38,6 +38,20 @@ NODE *(*str2number)(NODE *) = r_force_number;
NODE *(*format_val)(const char *, int, NODE *) = r_format_val;
int (*cmp_numbers)(const NODE *, const NODE *) = cmp_awknums;
+/* is_hex --- return true if a string looks like a hex value */
+
+static bool
+is_hex(const char *str)
+{
+ if (*str == '-' || *str == '+')
+ str++;
+
+ if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X'))
+ return true;
+
+ return false;
+}
+
/* force_number --- force a value to be numeric */
NODE *
@@ -94,8 +108,7 @@ r_force_number(NODE *n)
|| (! do_posix /* not POSIXLY paranoid and */
&& (is_alpha((unsigned char) *cp) /* letter, or */
/* CANNOT do non-decimal and saw 0x */
- || (! do_non_decimal_data && cp[0] == '0'
- && (cp[1] == 'x' || cp[1] == 'X'))))) {
+ || (! do_non_decimal_data && is_hex(cp))))) {
goto badnum;
}