-
Notifications
You must be signed in to change notification settings - Fork 104
Fix #653: defined() not recognizing ## token paste in its operand (GNU extension) #694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2249,33 +2249,38 @@ namespace simplecpp { | |
| } | ||
|
|
||
| if (tok->str() == DEFINED) { | ||
| const Token * const tok2 = tok->next; | ||
| const Token * const tok3 = tok2 ? tok2->next : nullptr; | ||
| const Token * const tok4 = tok3 ? tok3->next : nullptr; | ||
| const Token *defToken = nullptr; | ||
| const Token *lastToken = nullptr; | ||
| if (sameline(tok, tok4) && tok2->op == '(' && tok3->name && tok4->op == ')') { | ||
| defToken = tok3; | ||
| lastToken = tok4; | ||
| } else if (sameline(tok,tok2) && tok2->name) { | ||
| defToken = lastToken = tok2; | ||
| std::string macroName; | ||
| TokenList temp(files); | ||
| const Token *argTok = tok->next; | ||
| bool expectParen = false; | ||
| if (argTok->op == '(') { | ||
| argTok = argTok->next; | ||
| expectParen = true; | ||
| } | ||
| if (defToken) { | ||
| std::string macroName = defToken->str(); | ||
| if (defToken->next && defToken->next->op == '#' && defToken->next->next && defToken->next->next->op == '#' && defToken->next->next->next && defToken->next->next->next->name && sameline(defToken,defToken->next->next->next)) { | ||
| TokenList temp(files); | ||
| if (expandArg(temp, defToken, parametertokens)) | ||
| macroName = temp.cback()->str(); | ||
| if (expandArg(temp, defToken->next->next->next, parametertokens)) | ||
| macroName += temp.cback() ? temp.cback()->str() : ""; | ||
| else | ||
| macroName += defToken->next->next->next->str(); | ||
| lastToken = defToken->next->next->next; | ||
| while (argTok->name) { | ||
| if (expandArg(temp, argTok, parametertokens)) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure that we should expand macros unless they are operands. will this work: the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It works, it takes a different execution path. |
||
| macroName += temp.cback() ? temp.cback()->str() : ""; | ||
| else | ||
| macroName += argTok->str(); | ||
| argTok = argTok->next; | ||
| if (!sameline(tok, argTok)) | ||
| break; | ||
| if (argTok && argTok->str() == "#") { | ||
|
ludviggunne marked this conversation as resolved.
Outdated
|
||
| if (!argTok->next || argTok->next->str() != "#") | ||
| throw Error(argTok->location, "Expected '#'"); | ||
| argTok = argTok->next->next; | ||
|
ludviggunne marked this conversation as resolved.
|
||
| } else { | ||
| break; | ||
| } | ||
| const bool def = (macros.find(macroName) != macros.end()); | ||
| output.push_back(newMacroToken(def ? "1" : "0", loc, true)); | ||
| return lastToken->next; | ||
| } | ||
| if (expectParen) { | ||
| if (!sameline(tok, argTok) && argTok->op != ')') | ||
| throw Error(argTok->location, "Expected ')'"); | ||
| argTok = argTok->next; | ||
| } | ||
| const bool def = (macros.find(macroName) != macros.end()); | ||
| output.push_back(newMacroToken(def ? "1" : "0", loc, true)); | ||
| return argTok; | ||
| } | ||
|
|
||
| output.push_back(newMacroToken(tok->str(), loc, true, tok)); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we used to prevent null pointer dereference when
tok->nextis nullThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems that sameline is not used properly anymore.