"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/teststl.cpp" between
cppcheck-1.86.tar.gz and cppcheck-1.87.tar.gz

About: Cppcheck is a static analysis tool for C/C++ code. It checks for memory leaks, mismatching allocation-deallocation, buffer overrun, and many more.

teststl.cpp  (cppcheck-1.86):teststl.cpp  (cppcheck-1.87)
/* /*
* Cppcheck - A tool for static C/C++ code analysis * Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2018 Cppcheck team. * Copyright (C) 2007-2019 Cppcheck team.
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
skipping to change at line 36 skipping to change at line 36
#include <string> #include <string>
class TestStl : public TestFixture { class TestStl : public TestFixture {
public: public:
TestStl() : TestFixture("TestStl") { TestStl() : TestFixture("TestStl") {
} }
private: private:
Settings settings; Settings settings;
void run() override { void run() OVERRIDE {
settings.addEnabled("warning"); settings.addEnabled("warning");
settings.addEnabled("style"); settings.addEnabled("style");
settings.addEnabled("performance"); settings.addEnabled("performance");
LOAD_LIB_2(settings.library, "std.cfg"); LOAD_LIB_2(settings.library, "std.cfg");
TEST_CASE(outOfBounds); TEST_CASE(outOfBounds);
TEST_CASE(outOfBoundsIndexExpression); TEST_CASE(outOfBoundsIndexExpression);
TEST_CASE(iterator1); TEST_CASE(iterator1);
TEST_CASE(iterator2); TEST_CASE(iterator2);
skipping to change at line 265 skipping to change at line 265
"test.cpp:2:note:condition 's.size()==1'\n" "test.cpp:2:note:condition 's.size()==1'\n"
"test.cpp:3:note:Access out of bounds\n", errout.str()); "test.cpp:3:note:Access out of bounds\n", errout.str());
// Do not crash // Do not crash
checkNormal("void a() {\n" checkNormal("void a() {\n"
" std::string b[];\n" " std::string b[];\n"
" for (auto c : b)\n" " for (auto c : b)\n"
" c.data();\n" " c.data();\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
checkNormal("std::string f(std::string x) {\n"
" if (x.empty()) return {};\n"
" x[0];\n"
"}\n");
ASSERT_EQUALS("", errout.str());
checkNormal("std::string f(std::string x) {\n"
" if (x.empty()) return std::string{};\n"
" x[0];\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void outOfBoundsIndexExpression() { void outOfBoundsIndexExpression() {
setMultiline(); setMultiline();
checkNormal("void f(std::string s) {\n" checkNormal("void f(std::string s) {\n"
" s[s.size()] = 1;\n" " s[s.size()] = 1;\n"
"}"); "}");
ASSERT_EQUALS("test.cpp:2:error:Out of bounds access of s, index 's.size ()' is out of bounds.\n", errout.str()); ASSERT_EQUALS("test.cpp:2:error:Out of bounds access of s, index 's.size ()' is out of bounds.\n", errout.str());
 End of changes. 3 change blocks. 
2 lines changed or deleted 14 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)