summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-10-19 19:30:11 -0700
committerH. Peter Anvin <hpa@zytor.com>2008-10-19 19:30:11 -0700
commitca544db4b6de0cb994a2eef65cc2e5e47079254b (patch)
tree9fe5b8798b6f3aa93126268189a4488a2e9fc416
parent0ca00860dfde882f384658409a0d14a3b46fc108 (diff)
downloadnasm-ca544db4b6de0cb994a2eef65cc2e5e47079254b.tar.gz
preproc: correctly handle quoted strings inside %[...] constructs
We need to skip quoted strings when determining the ending point of %[...] constructs. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--preproc.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/preproc.c b/preproc.c
index e83abbe9..434383b5 100644
--- a/preproc.c
+++ b/preproc.c
@@ -779,7 +779,7 @@ static char *read_line(void)
*/
static Token *tokenize(char *line)
{
- char *p = line;
+ char c, *p = line;
enum pp_token_type type;
Token *list = NULL;
Token *t, **tail = &list;
@@ -810,12 +810,23 @@ static Token *tokenize(char *line)
int lvl = 1;
line += 2; /* Skip the leading %[ */
p++;
- while (*p) {
- if (*p == ']') {
- if (!--lvl)
- break;
- } else if (*p == '%' && p[1] == '[') {
- lvl++;
+ while (lvl && (c = *p)) {
+ switch (c) {
+ case ']':
+ lvl--;
+ break;
+ case '%':
+ p++;
+ if (*p == '[')
+ lvl++;
+ break;
+ case '\'':
+ case '\"':
+ case '`':
+ p = nasm_skip_string(p);
+ break;
+ default:
+ break;
}
p++;
}