* dtc: Cleanup \nnn and \xNN string escape handling
@ 2008-03-17 6:03 David Gibson
0 siblings, 0 replies; only message in thread
From: David Gibson @ 2008-03-17 6:03 UTC (permalink / raw)
To: Jon Loeliger; +Cc: linuxppc-dev
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>
---
data.c | 19 ++++++-------------
1 file changed, 6 insertions(+), 13 deletions(-)
Index: dtc/data.c
===================================================================
--- dtc.orig/data.c 2008-03-17 16:37:04.000000000 +1100
+++ dtc/data.c 2008-03-17 16:37:04.000000000 +1100
@@ -75,16 +75,11 @@ static char get_oct_char(const char *s,
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,
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;
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-03-17 6:03 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-17 6:03 dtc: Cleanup \nnn and \xNN string escape handling David Gibson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).