Skip to content

Commit

Permalink
Fix FP truncLongCastAssignment on Windows (f'up to #11953) (#6135)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Mar 20, 2024
1 parent 63eac64 commit 7211458
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/checktype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ void CheckType::signConversionError(const Token *tok, const ValueFlow::Value *ne
//---------------------------------------------------------------------------
// Checking for long cast of int result const long x = var1 * var2;
//---------------------------------------------------------------------------
static bool checkTypeCombination(const ValueType& src, const ValueType& tgt, const Settings& settings)
static bool checkTypeCombination(ValueType src, ValueType tgt, const Settings& settings)
{
static const std::pair<ValueType::Type, ValueType::Type> typeCombinations[] = {
{ ValueType::Type::INT, ValueType::Type::LONG },
Expand All @@ -310,6 +310,9 @@ static bool checkTypeCombination(const ValueType& src, const ValueType& tgt, con
{ ValueType::Type::DOUBLE, ValueType::Type::LONGDOUBLE },
};

src.reference = Reference::None;
tgt.reference = Reference::None;

const std::size_t sizeSrc = ValueFlow::getSizeOf(src, settings);
const std::size_t sizeTgt = ValueFlow::getSizeOf(tgt, settings);
if (!(sizeSrc > 0 && sizeTgt > 0 && sizeSrc < sizeTgt))
Expand Down
5 changes: 5 additions & 0 deletions test/testtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,11 @@ class TestType : public TestFixture {
" U u;\n"
"};\n", settings);
ASSERT_EQUALS("", errout_str()); // don't crash

check("void f(long& r, long i) {\n"
" r = 1 << i;\n"
"}\n", settingsWin);
ASSERT_EQUALS("", errout_str());
}

void longCastReturn() {
Expand Down

0 comments on commit 7211458

Please sign in to comment.