From 4cf56dac2b421a2034fe37618fbf81a6f5e903b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Debrard?= Date: Tue, 25 Jan 2011 09:57:58 +0100 Subject: [PATCH] Fix 2495 incorrect sizeof error message --- lib/checkother.cpp | 13 +++++++++++-- test/testother.cpp | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index d8e065610..3d1b53443 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -95,9 +95,18 @@ void CheckOther::checkSizeofForArrayParameter() const Token *declTok = Token::findmatch(_tokenizer->tokens(), "%varid%", tok->tokAt(tokIdx)->varId()); if (declTok) { - if ((Token::simpleMatch(declTok->next(), "[")) && !(Token::Match(declTok->next()->link(), "] = %str%")) && !(Token::simpleMatch(declTok->next()->link(), "] = {")) && !(Token::simpleMatch(declTok->next()->link(), "] ;"))) + if (Token::simpleMatch(declTok->next(), "[")) { - sizeofForArrayParameterError(tok); + declTok = declTok->next()->link(); + // multidimensional array + while (Token::simpleMatch(declTok->next(), "[")) + { + declTok = declTok->next()->link(); + } + if (!(Token::Match(declTok->next(), "= %str%")) && !(Token::simpleMatch(declTok->next(), "= {")) && !(Token::simpleMatch(declTok->next(), ";")) && !(Token::simpleMatch(declTok->next(), ","))) + { + sizeofForArrayParameterError(tok); + } } } } diff --git a/test/testother.cpp b/test/testother.cpp index f71d7eb97..be126778b 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1749,6 +1749,22 @@ private: ); ASSERT_EQUALS("", errout.str()); + // ticket 2495 + check("void f() {\n" + " static float col[][3]={\n" + " {1,0,0},\n" + " {0,0,1},\n" + " {0,1,0},\n" + " {1,0,1},\n" + " {1,0,1},\n" + " {1,0,1},\n" + " };\n" + " const int COL_MAX=sizeof(col)/sizeof(col[0]);\n" + "}\n" + ); + ASSERT_EQUALS("", errout.str()); + + }