Skip to content

Commit 4eed295

Browse files
authored
ValueFlow: Set values to parameters to longjmp and setjmp (#4040)
* ValueFlow: Set values to parameters to longjmp and setjmp * Format
1 parent 4fa2e3a commit 4eed295

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

lib/forwardanalyzer.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,13 @@ struct ForwardTraversal {
123123

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

test/testvalueflow.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3486,6 +3486,12 @@ class TestValueFlow : public TestFixture {
34863486
" exit(x);\n"
34873487
"}\n";
34883488
ASSERT_EQUALS(true, testValueOfXKnown(code, 3U, 1));
3489+
3490+
code = "void f(jmp_buf env) {\n"
3491+
" int x = 1;\n"
3492+
" longjmp(env, x);\n"
3493+
"}\n";
3494+
ASSERT_EQUALS(true, testValueOfXKnown(code, 3U, 1));
34893495
}
34903496

34913497
void valueFlowForwardTernary() {

0 commit comments

Comments
 (0)