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()
461
461
continue ;
462
462
if (!tok->valueType () || tok->valueType ()->pointer == 0 )
463
463
continue ;
464
- if (!MathLib::isIntHex (from->str ()) && from->getKnownIntValue () != 0 ) {
464
+ if (!MathLib::isIntHex (from->str ()) && from->hasKnownIntValue () && from-> getKnownIntValue () != 0 ) {
465
465
std::string format;
466
466
if (MathLib::isDec (from->str ()))
467
467
format = " decimal" ;
Original file line number Diff line number Diff line change @@ -2211,6 +2211,10 @@ class TestOther : public TestFixture {
2211
2211
2212
2212
checkIntToPointerCast("uint8_t* ptr = (uint8_t*)0x7000;"); // <- it's common in embedded code to cast address
2213
2213
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());
2214
2218
}
2215
2219
2216
2220
#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)
You can’t perform that action at this time.
0 commit comments