"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/testgarbage.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.

testgarbage.cpp  (cppcheck-1.86):testgarbage.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 <list> #include <list>
class TestGarbage : public TestFixture { class TestGarbage : public TestFixture {
public: public:
TestGarbage() : TestFixture("TestGarbage") { TestGarbage() : TestFixture("TestGarbage") {
} }
private: private:
Settings settings; Settings settings;
void run() override { void run() OVERRIDE {
settings.debugwarnings = true; settings.debugwarnings = true;
settings.addEnabled("style"); settings.addEnabled("style");
settings.addEnabled("warning"); settings.addEnabled("warning");
settings.addEnabled("portability"); settings.addEnabled("portability");
settings.addEnabled("performance"); settings.addEnabled("performance");
settings.addEnabled("information"); settings.addEnabled("information");
settings.inconclusive = true; settings.inconclusive = true;
settings.experimental = true; settings.experimental = true;
// don't freak out when the syntax is wrong // don't freak out when the syntax is wrong
skipping to change at line 234 skipping to change at line 234
TEST_CASE(garbageCode192); // #8386 (segmentation fault) TEST_CASE(garbageCode192); // #8386 (segmentation fault)
TEST_CASE(garbageCode193); // #8740 TEST_CASE(garbageCode193); // #8740
TEST_CASE(garbageCode194); // #8384 TEST_CASE(garbageCode194); // #8384
TEST_CASE(garbageCode195); // #8709 TEST_CASE(garbageCode195); // #8709
TEST_CASE(garbageCode196); // #8265 TEST_CASE(garbageCode196); // #8265
TEST_CASE(garbageCode197); // #8385 TEST_CASE(garbageCode197); // #8385
TEST_CASE(garbageCode198); // #8383 TEST_CASE(garbageCode198); // #8383
TEST_CASE(garbageCode199); // #8752 TEST_CASE(garbageCode199); // #8752
TEST_CASE(garbageCode200); // #8757 TEST_CASE(garbageCode200); // #8757
TEST_CASE(garbageCode201); // #8873 TEST_CASE(garbageCode201); // #8873
TEST_CASE(garbageCode202); // #8907
TEST_CASE(garbageCodeFuzzerClientMode1); // test cases created with the fuzzer client, mode 1 TEST_CASE(garbageCodeFuzzerClientMode1); // test cases created with the fuzzer client, mode 1
TEST_CASE(garbageValueFlow); TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase); TEST_CASE(garbageSymbolDatabase);
TEST_CASE(garbageAST); TEST_CASE(garbageAST);
TEST_CASE(templateSimplifierCrashes); TEST_CASE(templateSimplifierCrashes);
TEST_CASE(syntaxErrorFirstToken); // Make sure syntax errors are detecte d and reported TEST_CASE(syntaxErrorFirstToken); // Make sure syntax errors are detecte d and reported
TEST_CASE(syntaxErrorLastToken); // Make sure syntax errors are detected and reported TEST_CASE(syntaxErrorLastToken); // Make sure syntax errors are detected and reported
TEST_CASE(syntaxErrorCase); TEST_CASE(syntaxErrorCase);
skipping to change at line 285 skipping to change at line 286
tokenizer.simplifyTokenList2(); tokenizer.simplifyTokenList2();
// call all "runSimplifiedChecks" in all registered Check classes // call all "runSimplifiedChecks" in all registered Check classes
for (std::list<Check *>::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) { for (std::list<Check *>::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) {
(*it)->runSimplifiedChecks(&tokenizer, &settings, this); (*it)->runSimplifiedChecks(&tokenizer, &settings, this);
} }
return tokenizer.tokens()->stringifyList(false, false, false, true, fals e, 0, 0); return tokenizer.tokens()->stringifyList(false, false, false, true, fals e, 0, 0);
} }
std::string getSyntaxError(const char code[]) {
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
try {
tokenizer.tokenize(istr, "test.cpp");
} catch (InternalError& e) {
if (e.id != "syntaxError")
return "";
return "[test.cpp:" + MathLib::toString(e.token->linenr()) + "] " +
e.errorMessage;
}
return "";
}
void wrong_syntax1() { void wrong_syntax1() {
{ {
const char code[] ="TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;) )"; const char code[] ="TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;) )";
ASSERT_EQUALS("TR ( kvmpio , PROTO ( int rw ) , ARGS ( rw ) , TP_ ( aa . rw ; ) )", checkCode(code)); ASSERT_EQUALS("TR ( kvmpio , PROTO ( int rw ) , ARGS ( rw ) , TP_ ( aa . rw ; ) )", checkCode(code));
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
{ {
const char code[] ="struct A { template<int> struct { }; };"; const char code[] ="struct A { template<int> struct { }; };";
ASSERT_THROW(checkCode(code), InternalError); ASSERT_THROW(checkCode(code), InternalError);
skipping to change at line 812 skipping to change at line 826
void garbageCode96() { // #6807 void garbageCode96() { // #6807
ASSERT_THROW(checkCode("typedef J J[ ; typedef ( ) ( ) { ; } typedef J J ;] ( ) ( J cx ) { n } ;"), InternalError); // throw syntax error ASSERT_THROW(checkCode("typedef J J[ ; typedef ( ) ( ) { ; } typedef J J ;] ( ) ( J cx ) { n } ;"), InternalError); // throw syntax error
} }
void garbageCode97() { // #6808 void garbageCode97() { // #6808
ASSERT_THROW(checkCode("namespace A {> } class A{ { }} class A : T< ;"), InternalError); ASSERT_THROW(checkCode("namespace A {> } class A{ { }} class A : T< ;"), InternalError);
} }
void garbageCode98() { // #6838 void garbageCode98() { // #6838
ASSERT_THROW(checkCode("for (cocon To::ta@Taaaaaforconst oken aaaaaaaaaa aa5Dl()\n" ASSERT_THROW(checkCode("for (cocon To::ta@Taaaaaforconst oken aaaaaaaaaa aa5Dl()\n"
"const unsiged in;\n" "const unsigned in;\n"
"fon *tok = f);.s(Token i = d-)L;"), InternalErro r); "fon *tok = f);.s(Token i = d-)L;"), InternalErro r);
} }
void garbageCode99() { // #6726 void garbageCode99() { // #6726
ASSERT_THROW(checkCode("{ xs :: i(:) ! ! x/5 ! !\n" ASSERT_THROW(checkCode("{ xs :: i(:) ! ! x/5 ! !\n"
"i, :: a :: b integer, } foo2(x) :: j(:) \n" "i, :: a :: b integer, } foo2(x) :: j(:) \n"
"b type(*), d(:), a x :: end d(..), foo end\n" "b type(*), d(:), a x :: end d(..), foo end\n"
"foo4 b d(..), a a x type(*), b foo2 b"), Interna lError); "foo4 b d(..), a a x type(*), b foo2 b"), Interna lError);
} }
skipping to change at line 1008 skipping to change at line 1022
"{\n" "{\n"
" for(;;){ foo();\n" " for(;;){ foo();\n"
"}\n"), InternalError); "}\n"), InternalError);
ASSERT_THROW(checkCode("void f()\n" ASSERT_THROW(checkCode("void f()\n"
"{\n" "{\n"
" a[10;\n" " a[10;\n"
"}\n"), InternalError); "}\n"), InternalError);
{ {
errout.str("");
const char code[] = "{\n" const char code[] = "{\n"
" a(\n" " a(\n" // <- error
"}\n" "}\n"
"{\n" "{\n"
" b());\n" " b());\n"
"}\n"; "}\n";
Tokenizer tokenizer(&settings, this); ASSERT_EQUALS("[test.cpp:2] Unmatched '('. Configuration: ''.", getS
std::istringstream istr(code); yntaxError(code));
try { }
tokenizer.tokenize(istr, "test.cpp");
assertThrowFail(__FILE__, __LINE__); {
} catch (InternalError& e) { const char code[] = "void f() {\n"
ASSERT_EQUALS("Invalid number of character '(' when no macros ar " int x = 3) + 0;\n" // <- error: unmatched )
e defined.", e.errorMessage); "}\n";
ASSERT_EQUALS("syntaxError", e.id); ASSERT_EQUALS("[test.cpp:2] Unmatched ')'. Configuration: ''.", getS
ASSERT_EQUALS(2, e.token->linenr()); yntaxError(code));
} }
{
const char code[] = "void f() {\n"
" int x = (3] + 0;\n" // <- error: unmatched ]
"}\n";
ASSERT_EQUALS("[test.cpp:2] Unmatched ']'. Configuration: ''.", getS
yntaxError(code));
}
{
const char code[] = "void f() {\n" // <- error: unmatched {
" {\n"
"}\n";
ASSERT_EQUALS("[test.cpp:1] Unmatched '{'. Configuration: ''.", getS
yntaxError(code));
} }
} }
void garbageCode134() { void garbageCode134() {
// Ticket #5605, #5759, #5762, #5774, #5823, #6059 // Ticket #5605, #5759, #5762, #5774, #5823, #6059
ASSERT_THROW(checkCode("foo() template<typename T1 = T2 = typename = unu sed, T5 = = unused> struct tuple Args> tuple<Args...> { } main() { foo<int,int,i nt,int,int,int>(); }"), InternalError); ASSERT_THROW(checkCode("foo() template<typename T1 = T2 = typename = unu sed, T5 = = unused> struct tuple Args> tuple<Args...> { } main() { foo<int,int,i nt,int,int,int>(); }"), InternalError);
ASSERT_THROW(checkCode("( ) template < T1 = typename = unused> struct Ar gs { } main ( ) { foo < int > ( ) ; }"), InternalError); ASSERT_THROW(checkCode("( ) template < T1 = typename = unused> struct Ar gs { } main ( ) { foo < int > ( ) ; }"), InternalError);
ASSERT_THROW(checkCode("() template < T = typename = x > struct a {} { f <int> () }"), InternalError); ASSERT_THROW(checkCode("() template < T = typename = x > struct a {} { f <int> () }"), InternalError);
ASSERT_THROW(checkCode("template < T = typename = > struct a { f <int> } "), InternalError); ASSERT_THROW(checkCode("template < T = typename = > struct a { f <int> } "), InternalError);
checkCode("struct S { int i, j; }; " checkCode("struct S { int i, j; }; "
skipping to change at line 1558 skipping to change at line 1583
// #8757 // #8757
void garbageCode200() { void garbageCode200() {
ASSERT_THROW(checkCode("(){e break,{(case)!{e:[]}}}"), InternalError); ASSERT_THROW(checkCode("(){e break,{(case)!{e:[]}}}"), InternalError);
} }
// #8873 // #8873
void garbageCode201() { void garbageCode201() {
ASSERT_THROW(checkCode("void f() { std::string s=\"abc\"; return s + }") , InternalError); ASSERT_THROW(checkCode("void f() { std::string s=\"abc\"; return s + }") , InternalError);
} }
// #8907
void garbageCode202() {
ASSERT_THROW(checkCode("void f() { UNKNOWN_MACRO(return); }"), InternalE
rror);
ASSERT_THROW(checkCode("void f() { UNKNOWN_MACRO(throw); }"), InternalEr
ror);
}
void syntaxErrorFirstToken() { void syntaxErrorFirstToken() {
ASSERT_THROW(checkCode("&operator(){[]};"), InternalError); // #7818 ASSERT_THROW(checkCode("&operator(){[]};"), InternalError); // #7818
ASSERT_THROW(checkCode("*(*const<> (size_t); foo) { } *(*const (size_t)( ) ; foo) { }"), InternalError); // #6858 ASSERT_THROW(checkCode("*(*const<> (size_t); foo) { } *(*const (size_t)( ) ; foo) { }"), InternalError); // #6858
ASSERT_THROW(checkCode(">{ x while (y) z int = }"), InternalError); // # 4175 ASSERT_THROW(checkCode(">{ x while (y) z int = }"), InternalError); // # 4175
ASSERT_THROW(checkCode("&p(!{}e x){({(0?:?){({})}()})}"), InternalError) ; // #7118 ASSERT_THROW(checkCode("&p(!{}e x){({(0?:?){({})}()})}"), InternalError) ; // #7118
ASSERT_THROW(checkCode("<class T> { struct { typename D4:typename Base<T *> }; };"), InternalError); // #3533 ASSERT_THROW(checkCode("<class T> { struct { typename D4:typename Base<T *> }; };"), InternalError); // #3533
ASSERT_THROW(checkCode(" > template < . > struct Y < T > { = } ;\n"), In ternalError); // #6108 ASSERT_THROW(checkCode(" > template < . > struct Y < T > { = } ;\n"), In ternalError); // #6108
} }
void syntaxErrorLastToken() { void syntaxErrorLastToken() {
 End of changes. 9 change blocks. 
16 lines changed or deleted 53 lines changed or added

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