Skip to content

Commit e15ea39

Browse files
committed
avoid unchecked pointer dereference in preprocessToken()
1 parent 5cd15b3 commit e15ea39

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

simplecpp.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3227,14 +3227,14 @@ simplecpp::FileDataCache simplecpp::load(const simplecpp::TokenList &rawtokens,
32273227
return cache;
32283228
}
32293229

3230-
static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token **tok1, simplecpp::MacroMap &macros, std::vector<std::string> &files, simplecpp::OutputList *outputList)
3230+
static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token *&tok1, simplecpp::MacroMap &macros, std::vector<std::string> &files, simplecpp::OutputList *outputList)
32313231
{
3232-
const simplecpp::Token * const tok = *tok1;
3232+
const simplecpp::Token * const tok = tok1;
32333233
const simplecpp::MacroMap::const_iterator it = tok->name ? macros.find(tok->str()) : macros.end();
32343234
if (it != macros.end()) {
32353235
simplecpp::TokenList value(files);
32363236
try {
3237-
*tok1 = it->second.expand(value, tok, macros, files);
3237+
tok1 = it->second.expand(value, tok, macros, files);
32383238
} catch (const simplecpp::Macro::Error &err) {
32393239
if (outputList) {
32403240
simplecpp::Output out = {
@@ -3250,7 +3250,7 @@ static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token
32503250
} else {
32513251
if (!tok->comment)
32523252
output.push_back(new simplecpp::Token(*tok));
3253-
*tok1 = tok->next;
3253+
tok1 = tok->next;
32543254
}
32553255
return true;
32563256
}
@@ -3488,7 +3488,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
34883488
TokenList inc2(files);
34893489
if (!inc1.empty() && inc1.cfront()->name) {
34903490
const Token *inctok = inc1.cfront();
3491-
if (!preprocessToken(inc2, &inctok, macros, files, outputList)) {
3491+
if (!preprocessToken(inc2, inctok, macros, files, outputList)) {
34923492
output.clear();
34933493
return;
34943494
}
@@ -3657,7 +3657,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
36573657
maybeUsedMacros[rawtok->next->str()].push_back(rawtok->next->location);
36583658

36593659
const Token *tmp = tok;
3660-
if (!preprocessToken(expr, &tmp, macros, files, outputList)) {
3660+
if (!preprocessToken(expr, tmp, macros, files, outputList)) {
36613661
output.clear();
36623662
return;
36633663
}
@@ -3755,7 +3755,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
37553755
const Location loc(rawtok->location);
37563756
TokenList tokens(files);
37573757

3758-
if (!preprocessToken(tokens, &rawtok, macros, files, outputList)) {
3758+
if (!preprocessToken(tokens, rawtok, macros, files, outputList)) {
37593759
output.clear();
37603760
return;
37613761
}

0 commit comments

Comments
 (0)