The bug seems to be related to the C11 generic function in combination with the condition.
Calling a generic function outside the condition is not a problem.
Interestingly, the crash does not occur (at least not on my machine) when the condition is == instead of !=.
The POC is valid C11 code and compiles fine.
Can you reproduce this bug?
Best regards,
Tobias
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The crash happened on a , without astOperand1(). The AST is still broken.
The crash is currently avoided by a bailout in valueFlowConditionExpressions(): if (const Token* incompleteTok = findIncompleteVar(scope->bodyStart, scope->bodyEnd)) ... break;
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That seems to have been the situation right after the fix. Nowadays the crash is prevented by the second condition in if (!Token::Match(parent, "%cop%") && !(parent->str() == "(" && tok == parent->astOperand1())) in isUsedAsBool().
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
when analyzing the following C11 code,
cppcheck
crashes with a segmentation fault:The bug seems to be related to the C11 generic function in combination with the condition.
Calling a generic function outside the condition is not a problem.
Interestingly, the crash does not occur (at least not on my machine) when the condition is
==
instead of!=
.The POC is valid C11 code and compiles fine.
Can you reproduce this bug?
Best regards,
Tobias
Seems to have been fixed in head around Sep/Oct.
Thanks for your answer.
Then it must be just after the last release.
Compiling from main fixes the problem for me.
Fixed by https://github.com/danmar/cppcheck/commit/dd76504f8289289e942cae5f52dd63b8617f118a, which seems unrelated...
The same code without the macro did not crash.
Last edit: CHR 2023-12-08
Here's the stacktrace:
This started with 2.10 and has been bisected to https://github.com/danmar/cppcheck/commit/117a753b1006a1116829f053a1c8e3912e22bde1.
This was fixed in 2.13.0 and the fix has indeed been bisected to https://github.com/danmar/cppcheck/commit/dd76504f8289289e942cae5f52dd63b8617f118a.
This is really curious and should be looked into.
The crash happened on a
,
withoutastOperand1()
. The AST is still broken.The crash is currently avoided by a bailout in
valueFlowConditionExpressions()
:if (const Token* incompleteTok = findIncompleteVar(scope->bodyStart, scope->bodyEnd)) ... break;
That seems to have been the situation right after the fix. Nowadays the crash is prevented by the second condition in
if (!Token::Match(parent, "%cop%") && !(parent->str() == "(" && tok == parent->astOperand1()))
inisUsedAsBool()
.https://trac.cppcheck.net/ticket/12382