From 3a8d9b8c8761b620ab00c401b17fdcf98b8318d2 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 26 Jan 2023 22:09:55 +0100 Subject: [PATCH] Fix #11510 FP CastIntegerToAddressAtReturn with ternary operator (#4732) --- lib/symboldatabase.cpp | 10 ++++++++-- test/test64bit.cpp | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 39f18b904..713f979b9 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -6419,12 +6419,18 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, Source } } else if (ternary) { if (vt1->pointer != 0U && vt2 && vt2->pointer == 0U) { - setValueType(parent, *vt2); + if (vt2->isPrimitive()) + setValueType(parent, *vt1); + else + setValueType(parent, *vt2); return; } if (vt1->pointer == 0U && vt2 && vt2->pointer != 0U) { - setValueType(parent, *vt1); + if (vt1->isPrimitive()) + setValueType(parent, *vt2); + else + setValueType(parent, *vt1); return; } } diff --git a/test/test64bit.cpp b/test/test64bit.cpp index c6d560259..bd754967b 100644 --- a/test/test64bit.cpp +++ b/test/test64bit.cpp @@ -152,6 +152,11 @@ private: " std::array a = S::g(S::E::E0);\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("char* f(char* p) {\n" + " return p ? p : 0;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void structmember() {