From 5ed44e34322cb8f96b7e8703ab6535980a0bff5d Mon Sep 17 00:00:00 2001 From: eck Date: Thu, 13 Sep 1990 15:12:13 +0000 Subject: [PATCH] fixed error with # && ##-operators in non function-like macro's pass printable garbage characters on to parser --- lang/cem/cemcom.ansi/LLlex.c | 7 ++++--- lang/cem/cemcom.ansi/replace.c | 11 +++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lang/cem/cemcom.ansi/LLlex.c b/lang/cem/cemcom.ansi/LLlex.c index 14838cbad..fc1342a33 100644 --- a/lang/cem/cemcom.ansi/LLlex.c +++ b/lang/cem/cemcom.ansi/LLlex.c @@ -178,10 +178,11 @@ firstline: #ifndef NOPP garbage: #endif - if (040 < ch && ch < 0177) - lexerror("garbage char %c", ch); - else + if (040 < ch && ch < 0177) { + return ptok->tk_symb = ch; + } else { lexerror("garbage char \\%03o", ch); + } goto again; case STSIMP: /* a simple character, no part of compound token*/ return ptok->tk_symb = ch; diff --git a/lang/cem/cemcom.ansi/replace.c b/lang/cem/cemcom.ansi/replace.c index 3d62f3601..8543388cc 100644 --- a/lang/cem/cemcom.ansi/replace.c +++ b/lang/cem/cemcom.ansi/replace.c @@ -548,6 +548,7 @@ macro2buffer(repl, idf, args) */ register char *ptr = idf->id_macro->mc_text; int err = 0; + int func = idf->id_macro->mc_nps != -1; char *stringify(); ASSERT(ptr[idf->id_macro->mc_length] == '\0'); @@ -566,7 +567,7 @@ macro2buffer(repl, idf, args) ptr++; } while (*ptr != delim || *ptr == '\0'); add2repl(repl, *ptr++); - } else if (*ptr == '#') { + } else if (func && *ptr == '#') { if (*++ptr == '#') { register int tmpindex; /* ## - paste operator */ @@ -631,8 +632,9 @@ macro2buffer(repl, idf, args) repl->r_text[tmpindex] = TOKSEP; } } - } else /* # operator */ - ptr = stringify(repl, ptr, args); + } else { /* # operator */ + ptr = stringify(repl, ptr, args); + } } else if (*ptr & FORMALP) { /* insert actual parameter */ register int n = *ptr++ & 0177; @@ -658,8 +660,9 @@ macro2buffer(repl, idf, args) if (*(repl->r_ptr - 1) != TOKSEP) add2repl(repl, TOKSEP); - } else + } else { add2repl(repl, *ptr++); + } } if (err) lexerror("illegal use of the ## operator"); -- 2.34.1