diff --git a/lib/forwardanalyzer.cpp b/lib/forwardanalyzer.cpp index 5c726daa4..07460af58 100644 --- a/lib/forwardanalyzer.cpp +++ b/lib/forwardanalyzer.cpp @@ -123,9 +123,13 @@ struct ForwardTraversal { template )> 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 diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index b6b3f4bed..404c00a5a 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -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() {