Skip to content

Commit 11f1a9d

Browse files
Fix crash on ternary with omitted operand (#4673)
* Fix MSVC compiler warning * Fix crash on incomplete ternary operator * Revert "Fix crash on incomplete ternary operator" This reverts commit 28df0f0. * Handle ternary with omitted operand
1 parent bf11cdf commit 11f1a9d

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

lib/valueflow.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,6 +1744,8 @@ static bool isConvertedToIntegral(const Token* tok, const Settings* settings)
17441744

17451745
static bool isSameToken(const Token* tok1, const Token* tok2)
17461746
{
1747+
if (!tok1 || !tok2)
1748+
return false;
17471749
if (tok1->exprId() != 0 && tok1->exprId() == tok2->exprId())
17481750
return true;
17491751
if (tok1->hasKnownIntValue() && tok2->hasKnownIntValue())

test/testcmdlineparser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ class TestCmdlineParser : public TestFixture {
12651265
void valueFlowMaxIterations() {
12661266
REDIRECT;
12671267
const char * const argv[] = {"cppcheck", "--valueflow-max-iterations=0"};
1268-
settings.valueFlowMaxIterations = -1;
1268+
settings.valueFlowMaxIterations = SIZE_MAX;
12691269
ASSERT(defParser.parseFromArgs(2, argv));
12701270
ASSERT_EQUALS(0, settings.valueFlowMaxIterations);
12711271
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
@@ -1274,7 +1274,7 @@ class TestCmdlineParser : public TestFixture {
12741274
void valueFlowMaxIterations2() {
12751275
REDIRECT;
12761276
const char * const argv[] = {"cppcheck", "--valueflow-max-iterations=11"};
1277-
settings.valueFlowMaxIterations = -1;
1277+
settings.valueFlowMaxIterations = SIZE_MAX;
12781278
ASSERT(defParser.parseFromArgs(2, argv));
12791279
ASSERT_EQUALS(11, settings.valueFlowMaxIterations);
12801280
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);

test/testvalueflow.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6839,6 +6839,12 @@ class TestValueFlow : public TestFixture {
68396839
" std::shared_ptr<B> m;\n"
68406840
"};\n";
68416841
valueOfTok(code, "r");
6842+
6843+
code = "void g(int);\n"
6844+
"void f(int x, int y) {\n"
6845+
" g(x < y ? : 1);\n"
6846+
"};\n";
6847+
valueOfTok(code, "?");
68426848
}
68436849

68446850
void valueFlowHang() {

0 commit comments

Comments
 (0)