From: Peter Johnson Date: Fri, 17 Apr 2009 03:25:08 +0000 (-0000) Subject: tasm (tweaked nasm) preproc fixes: X-Git-Tag: v1.0.0~100 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bccb81d575c229c453f06fa891c2e69efc557544;p=yasm tasm (tweaked nasm) preproc fixes: - comments stripped before tokenization caused strings containing ';' to generate warnings (unterminated string) and incorrect output. - assume directive parsing did not properly handle ';' as end of line Also add tests for the above. Reported by: Rugxulo svn path=/trunk/yasm/; revision=2197 --- diff --git a/modules/preprocs/Makefile.inc b/modules/preprocs/Makefile.inc index 8d3f7cfd..aee9accd 100644 --- a/modules/preprocs/Makefile.inc +++ b/modules/preprocs/Makefile.inc @@ -1,9 +1,11 @@ # $Id$ +EXTRA_DIST += modules/preprocs/tasm/Makefile.inc EXTRA_DIST += modules/preprocs/nasm/Makefile.inc EXTRA_DIST += modules/preprocs/raw/Makefile.inc EXTRA_DIST += modules/preprocs/cpp/Makefile.inc +include modules/preprocs/tasm/Makefile.inc include modules/preprocs/nasm/Makefile.inc include modules/preprocs/raw/Makefile.inc include modules/preprocs/cpp/Makefile.inc diff --git a/modules/preprocs/nasm/nasm-pp.c b/modules/preprocs/nasm/nasm-pp.c index 0bbb0f3a..64733557 100644 --- a/modules/preprocs/nasm/nasm-pp.c +++ b/modules/preprocs/nasm/nasm-pp.c @@ -538,13 +538,10 @@ check_tasm_directive(char *line) char *p, *oldline, oldchar, *q, oldchar2; TMEndItem *end; - if ((p = strchr(line, ';'))) - *p = '\0'; - p = line; /* Skip whitespace */ - while (isspace(*p) && *p != 0) + while (isspace(*p) && *p != 0 && *p != ';') p++; /* Ignore nasm directives */ @@ -553,7 +550,7 @@ check_tasm_directive(char *line) /* Binary search for the directive name */ len = 0; - while (!isspace(p[len]) && p[len] != 0) + while (!isspace(p[len]) && p[len] != 0 && p[len] != ';') len++; if (!len) return line; @@ -871,10 +868,10 @@ check_tasm_directive(char *line) /* Skip whitespaces */ while (isspace(*q) && *q) q++; - while (*q) { + while (*q && *q != ';') { p = q; - for (; *q && *q != ':' && !isspace(*q); q++); - if (!*q) + for (; *q && *q != ';' && *q != ':' && !isspace(*q); q++); + if (!*q || *q == ';') break; /* segment register name */ for (assume = TAssumes; assume->segreg; assume++) @@ -888,20 +885,22 @@ check_tasm_directive(char *line) assume->segreg = nasm_strndup(p, q-p); assume[1].segreg = NULL; } - for (; *q && *q != ':' && isspace(*q); q++); + for (; *q && *q != ';' && *q != ':' && isspace(*q); q++); if (*q != ':') error(ERR_FATAL, "expected `:' instead of `%c'", *q); for (q++; *q && isspace(*q); q++); /* segment name */ p = q; - for (; *q && *q != ',' && !isspace(*q); q++); + for (; *q && *q != ';' && *q != ',' && !isspace(*q); q++); assume->segment = nasm_strndup(p, q-p); for (; *q && isspace(*q); q++); - if (*q && *q != ',') + if (*q && *q != ';' && *q != ',') error(ERR_FATAL, "expected `,' instead of `%c'", *q); - for (q++; *q && isspace(*q); q++); + if (*q && *q != ';') + q++; + for (; *q && isspace(*q); q++); } TAssumes[i].segreg = NULL; TAssumes = nasm_realloc(TAssumes, (i+1)*sizeof(*TAssumes)); diff --git a/modules/preprocs/tasm/Makefile.inc b/modules/preprocs/tasm/Makefile.inc new file mode 100644 index 00000000..588a3e8f --- /dev/null +++ b/modules/preprocs/tasm/Makefile.inc @@ -0,0 +1,5 @@ +# $Id$ + +EXTRA_DIST += modules/preprocs/tasm/tests/Makefile.inc + +include modules/preprocs/tasm/tests/Makefile.inc diff --git a/modules/preprocs/tasm/tests/Makefile.inc b/modules/preprocs/tasm/tests/Makefile.inc new file mode 100644 index 00000000..23450b4e --- /dev/null +++ b/modules/preprocs/tasm/tests/Makefile.inc @@ -0,0 +1,9 @@ +# $Id$ + +TESTS += modules/preprocs/tasm/tests/tasmpp_test.sh + +EXTRA_DIST += modules/preprocs/tasm/tests/tasmpp_test.sh +EXTRA_DIST += modules/preprocs/nasm/tests/tasm-assume-comment.asm +EXTRA_DIST += modules/preprocs/nasm/tests/tasm-assume-comment.hex +EXTRA_DIST += modules/preprocs/nasm/tests/tasm-comment-instr.asm +EXTRA_DIST += modules/preprocs/nasm/tests/tasm-comment-instr.hex diff --git a/modules/preprocs/tasm/tests/tasm-assume-comment.asm b/modules/preprocs/tasm/tests/tasm-assume-comment.asm new file mode 100644 index 00000000..6b7cc1bf --- /dev/null +++ b/modules/preprocs/tasm/tests/tasm-assume-comment.asm @@ -0,0 +1,3 @@ +assume cs:code,ds:code,es:code ; tiny model (CS=DS=ES) +assume ds:code,es:code; close comment +assume fs:code,gs:code diff --git a/modules/preprocs/tasm/tests/tasm-assume-comment.hex b/modules/preprocs/tasm/tests/tasm-assume-comment.hex new file mode 100644 index 00000000..e69de29b diff --git a/modules/preprocs/tasm/tests/tasm-comment-instr.asm b/modules/preprocs/tasm/tests/tasm-comment-instr.asm new file mode 100644 index 00000000..d93001b1 --- /dev/null +++ b/modules/preprocs/tasm/tests/tasm-comment-instr.asm @@ -0,0 +1 @@ +ansi_normal db 0x27,'[0;40;37m$' diff --git a/modules/preprocs/tasm/tests/tasm-comment-instr.hex b/modules/preprocs/tasm/tests/tasm-comment-instr.hex new file mode 100644 index 00000000..594d68f0 --- /dev/null +++ b/modules/preprocs/tasm/tests/tasm-comment-instr.hex @@ -0,0 +1,11 @@ +27 +5b +30 +3b +34 +30 +3b +33 +37 +6d +24 diff --git a/modules/preprocs/tasm/tests/tasmpp_test.sh b/modules/preprocs/tasm/tests/tasmpp_test.sh new file mode 100755 index 00000000..e3155b52 --- /dev/null +++ b/modules/preprocs/tasm/tests/tasmpp_test.sh @@ -0,0 +1,4 @@ +#! /bin/sh +# $Id$ +${srcdir}/out_test.sh tasmpp_test modules/preprocs/tasm/tests "tasm preproc" "-f bin -p tasm" "" +exit $?