summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlya Trofimovich <skvadrik@gmail.com>2023-05-13 05:23:13 +0100
committerGitHub <noreply@github.com>2023-05-12 21:23:13 -0700
commit811f24d0bfa234bd226301edb6f789320b6f8b5a (patch)
tree3594e98aa341942bda502d57c1f4402a82e59f7d
parent241bf4c42c2403f0ccae3d52cc610d5cec5d8c2e (diff)
downloadyasm-811f24d0bfa234bd226301edb6f789320b6f8b5a.tar.gz
GAS preprocessor: don't cut comments inside of string literals. (#81)
-rw-r--r--modules/preprocs/gas/gas-preproc.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/modules/preprocs/gas/gas-preproc.c b/modules/preprocs/gas/gas-preproc.c
index 61941bf9..0dd0531c 100644
--- a/modules/preprocs/gas/gas-preproc.c
+++ b/modules/preprocs/gas/gas-preproc.c
@@ -1049,6 +1049,32 @@ typedef int (*pp_fn2_t)(yasm_preproc_gas *pp, int param, const char *arg1, const
#define FN(f) ((pp_fn0_t) &(f))
+static char *find_str_bound(char *line)
+{
+ for (; line[0]; ++line) {
+ if (line[0] == '"') return line;
+ if (line[0] == '\\' && line[1] == '"') ++line;
+ }
+ return NULL;
+}
+
+static char *find_comment(char *line)
+{
+ char *c, *s;
+
+ for (c = line, s = line; (c = strstr(c, "/*")); s = c) {
+ for (;;) {
+ s = find_str_bound(s);
+ if (!s || s > c) return c;
+
+ s = find_str_bound(s + 1);
+ if (!s || s > c) return NULL;
+ }
+ }
+
+ return NULL;
+}
+
static void kill_comments(yasm_preproc_gas *pp, char *line)
{
int next = 2;
@@ -1064,7 +1090,7 @@ static void kill_comments(yasm_preproc_gas *pp, char *line)
cstart = line;
next = 0;
} else {
- cstart = strstr(line, "/*");
+ cstart = find_comment(line);
next = 2;
}