From f409861492b44fe9de66bbff67d361605cfeb56d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 18 Jan 2009 17:42:41 +0000 Subject: [PATCH] strPlusChar: Fixed false positives --- src/checkother.cpp | 10 +++++----- test/testother.cpp | 12 ++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/checkother.cpp b/src/checkother.cpp index 16632b8f0..6664e4b16 100644 --- a/src/checkother.cpp +++ b/src/checkother.cpp @@ -987,17 +987,17 @@ void CheckOther::strPlusChar() } // - else if (Token::Match(tok, "%str% + %any%")) + else if (Token::Match(tok, "[=(] %str% + %any%")) { // char constant.. - const char *s = tok->strAt(2); + const char *s = tok->strAt(3); if (*s == '\'') - _errorLogger->reportErr(ErrorMessage::strPlusChar(_tokenizer, tok)); + _errorLogger->reportErr(ErrorMessage::strPlusChar(_tokenizer, tok->next())); // char variable.. - unsigned int varid = tok->tokAt(2)->varId(); + unsigned int varid = tok->tokAt(3)->varId(); if (varid > 0 && varid < 10000 && charVars[varid]) - _errorLogger->reportErr(ErrorMessage::strPlusChar(_tokenizer, tok)); + _errorLogger->reportErr(ErrorMessage::strPlusChar(_tokenizer, tok->next())); } } } diff --git a/test/testother.cpp b/test/testother.cpp index c75a65eca..9d598b1ec 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -44,6 +44,7 @@ private: TEST_CASE(strPlusChar1); // "/usr" + '/' TEST_CASE(strPlusChar2); // "/usr" + ch + TEST_CASE(strPlusChar3); // ok: path + "/sub" + '/' } void check(const char code[]) @@ -201,6 +202,17 @@ private: ASSERT_EQUALS(std::string("[test.cpp:4]: Unusual pointer arithmetic\n"), errout.str()); } + void strPlusChar3() + { + // Strange looking pointer arithmetic.. + strPlusChar("void foo()\n" + "{\n" + " std::string temp = \"/tmp\";\n" + " std::string path = temp + '/' + \"sub\" + '/';\n" + "}\n"); + ASSERT_EQUALS(std::string(""), errout.str()); + } + }; REGISTER_TEST(TestOther)