File tree Expand file tree Collapse file tree 2 files changed +5
-1
lines changed Expand file tree Collapse file tree 2 files changed +5
-1
lines changed Original file line number Diff line number Diff line change @@ -461,7 +461,7 @@ void CheckOther::warningIntToPointerCast()
461461 continue ;
462462 if (!tok->valueType () || tok->valueType ()->pointer == 0 )
463463 continue ;
464- if (!MathLib::isIntHex (from->str ()) && from->getKnownIntValue () != 0 ) {
464+ if (!MathLib::isIntHex (from->str ()) && from->hasKnownIntValue () && from-> getKnownIntValue () != 0 ) {
465465 std::string format;
466466 if (MathLib::isDec (from->str ()))
467467 format = " decimal" ;
Original file line number Diff line number Diff line change @@ -2211,6 +2211,10 @@ class TestOther : public TestFixture {
22112211
22122212 checkIntToPointerCast("uint8_t* ptr = (uint8_t*)0x7000;"); // <- it's common in embedded code to cast address
22132213 ASSERT_EQUALS("", errout_str());
2214+
2215+ checkIntToPointerCast("struct S { int i; };\n" // #13886, don't crash
2216+ "int f() { return sizeof(((struct S*)0)->i); }");
2217+ ASSERT_EQUALS("", errout_str());
22142218 }
22152219
22162220#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)
You can’t perform that action at this time.
0 commit comments