diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index e19a1846b..9cd10645e 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -177,7 +177,7 @@ void CheckStl::outOfBounds() return false; const Token* sizeTok = v.tokvalue; if (sizeTok && sizeTok->isCast()) - sizeTok = sizeTok->astOperand1(); + sizeTok = sizeTok->astOperand2() ? sizeTok->astOperand2() : sizeTok->astOperand1(); const Token* containerTok = getContainerFromSize(container, sizeTok); if (!containerTok) return false; diff --git a/test/teststl.cpp b/test/teststl.cpp index 5a3193030..329e7d2ee 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -690,10 +690,16 @@ private: " if (i <= (int)v.size()) {\n" " if (v[i]) {}\n" " }\n" + " if (i <= static_cast(v.size())) {\n" + " if (v[i]) {}\n" + " }\n" "}\n"); ASSERT_EQUALS("test.cpp:3:warning:Either the condition 'i<=(int)v.size()' is redundant or 'i' can have the value v.size(). Expression 'v[i]' cause access out of bounds.\n" "test.cpp:2:note:condition 'i<=(int)v.size()'\n" - "test.cpp:3:note:Access out of bounds\n", + "test.cpp:3:note:Access out of bounds\n" + "test.cpp:6:warning:Either the condition 'i<=static_cast(v.size())' is redundant or 'i' can have the value v.size(). Expression 'v[i]' cause access out of bounds.\n" + "test.cpp:5:note:condition 'i<=static_cast(v.size())'\n" + "test.cpp:6:note:Access out of bounds\n", errout.str()); check("template\n"