From a479bd6b163053f82c4aee35f49b67ddea07bf8c Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sun, 17 May 2015 20:05:45 +0100 Subject: [PATCH] Fix for br977 - preprocessor macros substitute text inside token. When replacing macro formal parameters, the preprocessor should not replace matching strings that are not complete tokens. The test for this was incorrect, and failed when a match was found at the start of the replacement text. --- ivlpp/lexor.lex | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ivlpp/lexor.lex b/ivlpp/lexor.lex index ea84b86e0..5a95e4f6a 100644 --- a/ivlpp/lexor.lex +++ b/ivlpp/lexor.lex @@ -950,6 +950,11 @@ static size_t magic_cnt = 0; #define _STR1(x) #x #define _STR2(x) _STR1(x) +static int is_id_char(char c) +{ + return isalnum((int)c) || c == '_' || c == '$'; +} + /* * Find an argument, but only if it is not directly preceded by something * that would make it part of another simple identifier ([a-zA-Z0-9_$]). @@ -964,12 +969,8 @@ static char *find_arg(char*ptr, char*head, char*arg) cp = strstr(cp, arg); if (!cp) break; - /* If we are not at the start of the string verify that this - * match is not in the middle of another identifier. - */ - if (cp != head && - (isalnum((int)*(cp-1)) || *(cp-1) == '_' || *(cp-1) == '$' || - isalnum((int)*(cp+len)) || *(cp+len) == '_' || *(cp+len) == '$')) { + /* Verify that this match is not in the middle of another identifier. */ + if ((cp != head && is_id_char(cp[-1])) || is_id_char(cp[len])) { cp++; continue; }