diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 123a9fce2ee..c36c37ead8f 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -461,7 +461,7 @@ void CheckOther::warningIntToPointerCast() continue; if (!tok->valueType() || tok->valueType()->pointer == 0) continue; - if (!MathLib::isIntHex(from->str()) && from->getKnownIntValue() != 0) { + if (!MathLib::isIntHex(from->str()) && from->hasKnownIntValue() && from->getKnownIntValue() != 0) { std::string format; if (MathLib::isDec(from->str())) format = "decimal"; diff --git a/test/testother.cpp b/test/testother.cpp index c126675a84b..d59e053c86e 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2211,6 +2211,10 @@ class TestOther : public TestFixture { checkIntToPointerCast("uint8_t* ptr = (uint8_t*)0x7000;"); // <- it's common in embedded code to cast address ASSERT_EQUALS("", errout_str()); + + checkIntToPointerCast("struct S { int i; };\n" // #13886, don't crash + "int f() { return sizeof(((struct S*)0)->i); }"); + ASSERT_EQUALS("", errout_str()); } #define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)