Skip to content

Commit 344e62a

Browse files
committed
abort preprocessing on syntax errors
1 parent 8eee9e2 commit 344e62a

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

simplecpp.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3117,12 +3117,13 @@ static void simplifyComments(simplecpp::TokenList &expr)
31173117
}
31183118
}
31193119

3120-
static long long evaluate(simplecpp::TokenList &expr, const simplecpp::DUI &dui, const std::map<std::string, std::size_t> &sizeOfType, simplecpp::OutputList *outputList)
3120+
static long long evaluate(simplecpp::TokenList &expr, const simplecpp::DUI &dui, const std::map<std::string, std::size_t> &sizeOfType, simplecpp::OutputList *outputList, bool &ok)
31213121
{
31223122
simplifyComments(expr);
31233123
simplifySizeof(expr, sizeOfType);
31243124
simplifyHasInclude(expr, dui);
3125-
if (!simplifyName(expr, outputList))
3125+
ok = simplifyName(expr, outputList);
3126+
if (!ok)
31263127
return 0;
31273128
simplifyNumbers(expr);
31283129
expr.constFold();
@@ -3828,17 +3829,20 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
38283829
tok = tmp->previous;
38293830
}
38303831
try {
3832+
bool ok = true;
38313833
if (ifCond) {
38323834
std::string E;
38333835
for (const simplecpp::Token *tok = expr.cfront(); tok; tok = tok->next)
38343836
E += (E.empty() ? "" : " ") + tok->str();
3835-
const long long result = evaluate(expr, dui, sizeOfType, outputList);
3837+
const long long result = evaluate(expr, dui, sizeOfType, outputList, ok);
38363838
conditionIsTrue = (result != 0);
38373839
ifCond->push_back(IfCond(rawtok->location, E, result));
38383840
} else {
3839-
const long long result = evaluate(expr, dui, sizeOfType, outputList);
3841+
const long long result = evaluate(expr, dui, sizeOfType, outputList, ok);
38403842
conditionIsTrue = (result != 0);
38413843
}
3844+
if (!ok)
3845+
return;
38423846
} catch (const std::exception &e) {
38433847
if (outputList) {
38443848
Output out(rawtok->location.files);

0 commit comments

Comments
 (0)