summaryrefslogtreecommitdiff
path: root/node.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2016-06-01 11:40:01 -0400
committerArnold D. Robbins <arnold@skeeve.com>2016-06-01 11:40:01 -0400
commit2ec9d8362cb2d85891417c2ffd98ea74377b2c12 (patch)
treece13ad6660d65559c4fdff3e44de99c44ef81d8b /node.c
parent0e02913c51b1d737b4d283901e22c57b954e65ae (diff)
parent9867841a4767347cd89c9fd0127db3c7eaf943e6 (diff)
downloadgawk-2ec9d8362cb2d85891417c2ffd98ea74377b2c12.tar.gz
Merge branch 'gawk-4.1-stable'
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 9227cf2d..93823270 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 *
@@ -96,8 +110,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))))) {
return n;
}