Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FP truncLongCastAssignment on Windows (f'up to #11953) #6135

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading