Dont traverse conditions multiple times (#2574)

This commit is contained in:
Paul Fultz II 2020-03-20 04:37:16 -05:00 committed by GitHub
parent f2527f5340
commit 7fd3580f21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 2 deletions

View File

@ -2,6 +2,7 @@
#include "astutils.h"
#include "settings.h"
#include "symboldatabase.h"
#include "token.h"
#include <functional>
@ -70,8 +71,6 @@ struct ForwardTraversal {
Progress traverseConditional(T* tok, F f, bool traverseUnknown) {
if (Token::Match(tok, "?|&&|%oror%")) {
T* condTok = tok->astOperand1();
if (traverseRecursive(condTok, f, traverseUnknown) == Progress::Break)
return Progress::Break;
T* childTok = tok->astOperand2();
bool checkThen, checkElse;
std::tie(checkThen, checkElse) = evalCond(condTok);

View File

@ -132,6 +132,7 @@ private:
TEST_CASE(valueFlowCrashIncompleteCode);
TEST_CASE(valueFlowCrash);
TEST_CASE(valueFlowHang);
TEST_CASE(valueFlowCrashConstructorInitialization);
}
@ -4454,6 +4455,49 @@ private:
valueOfTok(code, "x");
}
void valueFlowHang() {
const char* code;
// #9659
code = "float arr1[4][4] = {0.0};\n"
"float arr2[4][4] = {0.0};\n"
"void f() {\n"
" if(arr1[0][0] == 0.0 &&\n"
" arr1[0][1] == 0.0 &&\n"
" arr1[0][2] == 0.0 &&\n"
" arr1[0][3] == 0.0 &&\n"
" arr1[1][0] == 0.0 &&\n"
" arr1[1][1] == 0.0 &&\n"
" arr1[1][2] == 0.0 &&\n"
" arr1[1][3] == 0.0 &&\n"
" arr1[2][0] == 0.0 &&\n"
" arr1[2][1] == 0.0 &&\n"
" arr1[2][2] == 0.0 &&\n"
" arr1[2][3] == 0.0 &&\n"
" arr1[3][0] == 0.0 &&\n"
" arr1[3][1] == 0.0 &&\n"
" arr1[3][2] == 0.0 &&\n"
" arr1[3][3] == 0.0 &&\n"
" arr2[0][0] == 0.0 &&\n"
" arr2[0][1] == 0.0 &&\n"
" arr2[0][2] == 0.0 &&\n"
" arr2[0][3] == 0.0 &&\n"
" arr2[1][0] == 0.0 &&\n"
" arr2[1][1] == 0.0 &&\n"
" arr2[1][2] == 0.0 &&\n"
" arr2[1][3] == 0.0 &&\n"
" arr2[2][0] == 0.0 &&\n"
" arr2[2][1] == 0.0 &&\n"
" arr2[2][2] == 0.0 &&\n"
" arr2[2][3] == 0.0 &&\n"
" arr2[3][0] == 0.0 &&\n"
" arr2[3][1] == 0.0 &&\n"
" arr2[3][2] == 0.0 &&\n"
" arr2[3][3] == 0.0\n"
" ) {}\n"
"}\n";
valueOfTok(code, "x");
}
void valueFlowCrashConstructorInitialization() { // #9577
const char* code;
code = "void Error()\n"