ValueFlow: Set values to parameters to longjmp and setjmp (#4040)

* ValueFlow: Set values to parameters to longjmp and setjmp

* Format
This commit is contained in:
Paul Fultz II 2022-04-22 23:18:55 -05:00 committed by GitHub
parent 4fa2e3ac87
commit 4eed29502c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -123,9 +123,13 @@ struct ForwardTraversal {
template<class T, class F, REQUIRES("T must be a Token class", std::is_convertible<T*, const Token*> )>
Progress traverseTok(T* tok, F f, bool traverseUnknown, T** out = nullptr) {
if (Token::Match(tok, "asm|goto|setjmp|longjmp"))
if (Token::Match(tok, "asm|goto"))
return Break(Analyzer::Terminate::Bail);
else if (Token::simpleMatch(tok, "continue")) {
else if (Token::Match(tok, "setjmp|longjmp (")) {
// Traverse the parameters of the function before escaping
traverseRecursive(tok->next()->astOperand2(), f, traverseUnknown);
return Break(Analyzer::Terminate::Bail);
} else if (Token::simpleMatch(tok, "continue")) {
if (loopEnds.empty())
return Break(Analyzer::Terminate::Escape);
// If we are in a loop then jump to the end

View File

@ -3486,6 +3486,12 @@ private:
" exit(x);\n"
"}\n";
ASSERT_EQUALS(true, testValueOfXKnown(code, 3U, 1));
code = "void f(jmp_buf env) {\n"
" int x = 1;\n"
" longjmp(env, x);\n"
"}\n";
ASSERT_EQUALS(true, testValueOfXKnown(code, 3U, 1));
}
void valueFlowForwardTernary() {