summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2008-03-17 17:03:47 +1100
committerJon Loeliger <jdl@loeliger.com>2008-03-23 08:00:33 -0500
commit2192d46dfdbb05cea13c853f7579b1386cdc4380 (patch)
treea762d64bccd85c6af0633b9aaa6de6087a95e50d /data.c
parent3bdd393965aa1f35c293074e6701b9c550aeae54 (diff)
downloaddtc-2192d46dfdbb05cea13c853f7579b1386cdc4380.tar.gz
dtc: Cleanup \nnn and \xNN string escape handling
Several small cleanups to the handling of octal and hex string escapes: - Use strncmp() instead dof what were essentially open-coded versions of the same, with short fixed lengths. - The call path to get_oct_char() means an empty escape is not possible. So replace the error message in this case with an assert. - Use die() instead of a non-fatal error message if get_hex_char() is given an empty escape. Change error message to close match gcc's in the same circumstance. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'data.c')
-rw-r--r--data.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/data.c b/data.c
index 0ee1010..0a1d81e 100644
--- a/data.c
+++ b/data.c
@@ -75,16 +75,11 @@ static char get_oct_char(const char *s, int *i)
long val;
x[3] = '\0';
- x[0] = s[(*i)];
- if (x[0]) {
- x[1] = s[(*i)+1];
- if (x[1])
- x[2] = s[(*i)+2];
- }
+ strncpy(x, s + *i, 3);
val = strtol(x, &endx, 8);
- if ((endx - x) == 0)
- fprintf(stderr, "Empty \\nnn escape\n");
+
+ assert(endx > x);
(*i) += endx - x;
return val;
@@ -97,13 +92,11 @@ static char get_hex_char(const char *s, int *i)
long val;
x[2] = '\0';
- x[0] = s[(*i)];
- if (x[0])
- x[1] = s[(*i)+1];
+ strncpy(x, s + *i, 2);
val = strtol(x, &endx, 16);
- if ((endx - x) == 0)
- fprintf(stderr, "Empty \\x escape\n");
+ if (!(endx > x))
+ die("\\x used with no following hex digits\n");
(*i) += endx - x;
return val;