summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-06-02 10:02:36 -0700
committerH. Peter Anvin <hpa@zytor.com>2008-06-02 10:02:36 -0700
commite46fec66ca915a903927e4fd3b1abac15c218f8a (patch)
tree9410a3ca9a2ce3422767287ae471ef675cd58c56
parent1df123bdbfba703815345f5d82095e410710a9c6 (diff)
downloadnasm-e46fec66ca915a903927e4fd3b1abac15c218f8a.tar.gz
nasm_unquote: make code a little more uniform
Make the code a bit more consistent: - ndig is now always a countdown, and we always to the (p > escp+1) test to see if we got anything at all (this is to deal with stuff like \x without a digit.) - Add missing break; after 'v' (bug!). - Preinitialize nval to zero.
-rw-r--r--quote.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/quote.c b/quote.c
index 3003c033..67c78aac 100644
--- a/quote.c
+++ b/quote.c
@@ -233,6 +233,7 @@ size_t nasm_unquote(char *str)
case st_backslash:
state = st_start;
escp = p-1;
+ nval = 0;
switch (c) {
case 'a':
*q++ = 7;
@@ -258,19 +259,18 @@ size_t nasm_unquote(char *str)
case 'u':
state = st_ucs;
ndig = 4;
- nval = 0;
break;
case 'U':
state = st_ucs;
ndig = 8;
- nval = 0;
break;
case 'v':
*q++ = 11;
+ break;
case 'x':
case 'X':
state = st_hex;
- ndig = nval = 0;
+ ndig = 2;
break;
case '0':
case '1':
@@ -281,7 +281,7 @@ size_t nasm_unquote(char *str)
case '6':
case '7':
state = st_oct;
- ndig = 1;
+ ndig = 2; /* Up to two more digits */
nval = c - '0';
break;
default:
@@ -293,7 +293,7 @@ size_t nasm_unquote(char *str)
case st_oct:
if (c >= '0' && c <= '7') {
nval = (nval << 3) + (c - '0');
- if (++ndig >= 3) {
+ if (!--ndig) {
*q++ = nval;
state = st_start;
}
@@ -309,13 +309,13 @@ size_t nasm_unquote(char *str)
(c >= 'A' && c <= 'F') ||
(c >= 'a' && c <= 'f')) {
nval = (nval << 4) + numvalue(c);
- if (++ndig >= 2) {
+ if (--ndig) {
*q++ = nval;
state = st_start;
}
} else {
p--; /* Process this character again */
- *q++ = ndig ? nval : *escp;
+ *q++ = (p > escp+1) ? nval : *escp;
state = st_start;
}
break;
@@ -348,10 +348,10 @@ size_t nasm_unquote(char *str)
*q++ = nval;
break;
case st_hex:
- *q++ = ndig ? nval : *escp;
+ *q++ = (p > escp+1) ? nval : *escp;
break;
case st_ucs:
- if (ndig)
+ if (p > escp+1)
q = emit_utf8(q, nval);
else
*q++ = *escp;