diff --git a/CheckBufferOverrun.cpp b/CheckBufferOverrun.cpp index cc2109f18..9620525be 100644 --- a/CheckBufferOverrun.cpp +++ b/CheckBufferOverrun.cpp @@ -1,6 +1,6 @@ //--------------------------------------------------------------------------- #include "CheckBufferOverrun.h" -#include "Tokenize.h" +#include "tokenize.h" #include "CommonCheck.h" #include diff --git a/CheckClass.cpp b/CheckClass.cpp index f418210d7..242ded9ba 100644 --- a/CheckClass.cpp +++ b/CheckClass.cpp @@ -1,6 +1,6 @@ //--------------------------------------------------------------------------- #include "CheckClass.h" -#include "Tokenize.h" +#include "tokenize.h" #include "CommonCheck.h" #include #include @@ -181,7 +181,11 @@ static TOKEN * ClassChecking_VarList_RemoveAssigned(TOKEN *_tokens, struct VAR * if (strcmp(ftok->next->str,".")==0 || strcmp(ftok->next->str,"->")==0) { // The functions 'clear' and 'Clear' are supposed to initialize variable. +#ifdef __linux__ + if( strcasecmp( ftok->next->next->str,"clear") == 0) +#else if (stricmp(ftok->next->next->str,"clear") == 0) +#endif { for (struct VAR *var = varlist; var; var = var->next) { diff --git a/CheckHeaders.cpp b/CheckHeaders.cpp index 80c4ce60c..c407880b3 100644 --- a/CheckHeaders.cpp +++ b/CheckHeaders.cpp @@ -1,6 +1,6 @@ //--------------------------------------------------------------------------- #include "CheckHeaders.h" -#include "Tokenize.h" +#include "tokenize.h" #include "CommonCheck.h" #include #include @@ -61,7 +61,11 @@ void WarningIncludeHeader() const char *includefile = includetok->next->str; while (hfile < Files.size()) { +#ifdef __linux__ + if (strcasecmp(Files[hfile].c_str(), includefile) == 0) +#else if (stricmp(Files[hfile].c_str(), includefile) == 0) +#endif break; hfile++; } @@ -90,21 +94,14 @@ void WarningIncludeHeader() indentlevel++; else if (tok1->str[0] == '}') - { - if (indentlevel > 0) - indentlevel--; - } - + indentlevel--; + if (indentlevel != 0) continue; - // namespace.. - if (match(tok1,"namespace var {")) - tok1 = gettok(tok1,2); - // Class or namespace declaration.. // -------------------------------------- - else if (match(tok1,"class var {") || match(tok1,"class var :")) + if (match(tok1,"class var {") || match(tok1,"class var :") || match(tok1,"namespace var {")) classlist.push_back(getstr(tok1, 1)); // Variable declaration.. @@ -133,8 +130,8 @@ void WarningIncludeHeader() tok1 = tok1->next; } } - - // function.. + + // function.. // -------------------------------------- else if (match(tok1,"type var (")) namelist.push_back(getstr(tok1, 1)); @@ -206,21 +203,7 @@ void WarningIncludeHeader() } if ( ! NeedDeclaration ) - { - if (std::find(classlist.begin(),classlist.end(),tok1->str ) != classlist.end()) - { - if ( strcmp(getstr(tok1, 1), "*") == 0 ) - { - NeedDeclaration = true; - } - - else - { - Needed = true; - break; - } - } - } + NeedDeclaration = (std::find(classlist.begin(),classlist.end(),tok1->str ) != classlist.end()); } diff --git a/CheckMemoryLeak.cpp b/CheckMemoryLeak.cpp index d9ac78b65..b55b64f57 100644 --- a/CheckMemoryLeak.cpp +++ b/CheckMemoryLeak.cpp @@ -9,7 +9,11 @@ #include #include +#ifdef __linux__ +#include +#else #include // <- memset +#endif //--------------------------------------------------------------------------- @@ -24,6 +28,7 @@ struct _variable + //--------------------------------------------------------------------------- // Checks for memory leaks inside function.. //--------------------------------------------------------------------------- diff --git a/CheckOther.cpp b/CheckOther.cpp index a8dc97f7a..12a8c46e1 100644 --- a/CheckOther.cpp +++ b/CheckOther.cpp @@ -1,6 +1,6 @@ //--------------------------------------------------------------------------- #include "CheckOther.h" -#include "Tokenize.h" +#include "tokenize.h" #include "CommonCheck.h" #include #include @@ -249,7 +249,7 @@ void WarningIf() { if (!newstatement || strcmp(tok->str,"if")) { - newstatement = (strchr("{};",tok->str[0]) != NULL); + newstatement = (strchr("{};",tok->str[0])); continue; } diff --git a/Makefile b/Makefile index 3746c75ec..a73b17aa4 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,13 @@ +SRCS=CheckBufferOverrun.cpp CheckClass.cpp CheckHeaders.cpp CheckMemoryLeak.cpp CheckOther.cpp CommonCheck.cpp Statements.cpp test.cpp tokenize.cpp +OBJS=$(SRCS:%.cpp=%.o) + +%.o: %.cpp + gxx -Wall -pedantic -I. -o $@ -c $^ -all: - gxx -Wall -pedantic -o cppcheck.exe main.cpp Tokenize.cpp Statements.cpp CheckBufferOverrun.cpp CheckClass.cpp CheckHeaders.cpp CheckMemoryLeak.cpp CheckOther.cpp CommonCheck.cpp - gxx -Wall -pedantic -o tok.exe testtok.cpp Tokenize.cpp CommonCheck.cpp - +all: ${OBJS} main.o + gxx -o cppcheck $^ +test: ${OBJS} TestTok.o + gxx -o cppcheck_test $^ +clean: + rm -f *.o cppcheck_test cppcheck diff --git a/cppcheck.bpr b/cppcheck.bpr index 1055ed10e..5fc2837a2 100644 --- a/cppcheck.bpr +++ b/cppcheck.bpr @@ -114,7 +114,7 @@ Item0=_DEBUG DebugSourceDirs=$(BCB)\source\vcl [Parameters] -RunParams=testbufferoverrun5\testbufferoverrun5.cpp +RunParams=-w testif5\testif5.cpp Launcher= UseLauncher=0 DebugCWD= diff --git a/main.cpp b/main.cpp index 45c1ebaba..5a432cb1c 100644 --- a/main.cpp +++ b/main.cpp @@ -6,7 +6,7 @@ #include #include "tokenize.h" // <- Tokenizer -#include "statements.h" // <- Statement list +#include "Statements.h" // <- Statement list #include "CheckMemoryLeak.h" #include "CheckBufferOverrun.h" @@ -31,10 +31,18 @@ int main(int argc, char* argv[]) const char *fname = NULL; for (int i = 1; i < argc; i++) { +#ifdef __linux__ + if(strcasecmp(argv[i],"--debug") == 0) +#else if (stricmp(argv[i],"--debug") == 0) +#endif Debug = true; +#ifdef __linux__ + else if (strcasecmp(argv[i],"-w") == 0) +#else else if (stricmp(argv[i],"-w") == 0) +#endif ShowWarnings = true; else @@ -105,7 +113,11 @@ static void CppCheck(const char FileName[]) // Warning upon c-style pointer casts const char *ext = strrchr(FileName, '.'); +#ifdef __linux__ + if (ext && strcasecmp(ext,".c")) +#else if (ext && stricmp(ext,".c")) +#endif WarningOldStylePointerCast(); // Use standard functions instead diff --git a/testclass13/err.msg b/testclass13/err.msg new file mode 100644 index 000000000..e69de29bb diff --git a/testclass13/testclass13.cpp b/testclass13/testclass13.cpp new file mode 100644 index 000000000..28f8c112a --- /dev/null +++ b/testclass13/testclass13.cpp @@ -0,0 +1,14 @@ + + +class clKalle +{ +private: + int i; +public: + clKalle(); +}; + +clKalle::clKalle() +{ + +} diff --git a/testclass13/warn.msg b/testclass13/warn.msg new file mode 100644 index 000000000..e69de29bb diff --git a/tokenize.cpp b/tokenize.cpp index 06abd584c..784138dce 100644 --- a/tokenize.cpp +++ b/tokenize.cpp @@ -10,6 +10,7 @@ #include #include // <- strtoul +#include //--------------------------------------------------------------------------- @@ -75,7 +76,8 @@ static void Define(const char Name[], const char Value[]) char str[50]; unsigned long value = strtoul(Value+2, NULL, 16); free(strValue); - strValue = strdup(itoa(value, str, 10)); + sprintf(str, "%d", value); + strValue = strdup(str); } DefineSymbol *NewSym = new DefineSymbol; @@ -113,7 +115,7 @@ static void addtoken(const char str[], const unsigned int lineno, const unsigned if (strncmp(str,"0x",2)==0) { unsigned int value = strtoul(str+2, NULL, 16); - itoa(value, str2, 10); + sprintf( str2, "%d", value ); } TOKEN *newtoken = new TOKEN; @@ -248,7 +250,11 @@ void Tokenize(const char FileName[]) // Has this file been tokenized already? for (unsigned int i = 0; i < Files.size(); i++) { +#ifdef __linux__ + if( strcasecmp(Files[i].c_str(), FileName) == 0 ) +#else if ( stricmp(Files[i].c_str(), FileName) == 0 ) +#endif return; } @@ -668,7 +674,8 @@ void SimplifyTokenList() free(tok->str); char str[10]; // 'sizeof(type *)' has the same size as 'sizeof(char *)' - tok->str = strdup(itoa(sizeof(char *), str, 10)); + sprintf( str, "%d", sizeof(char *)); + tok->str = strdup( str ); for (int i = 0; i < 4; i++) { @@ -684,8 +691,8 @@ void SimplifyTokenList() { free(tok->str); char str[10]; - tok->str = strdup(itoa(size, str, 10)); - + sprintf( str, "%d", size ); + tok->str = strdup( str ); for (int i = 0; i < 3; i++) { DeleteNextToken(tok); @@ -730,8 +737,8 @@ void SimplifyTokenList() { free(tok2->str); char str[20]; - tok2->str = strdup(itoa(total_size, str, 10)); - + sprintf( str, "%d", total_size); + tok2->str = strdup(str ); // Delete the other tokens.. for (int i = 0; i < 3; i++) { @@ -782,7 +789,8 @@ void SimplifyTokenList() tok = tok->next; free(tok->str); char str[10]; - tok->str = strdup(itoa(i1,str,10)); + sprintf(str,"%d", i1); + tok->str = strdup(str); for (int i = 0; i < 2; i++) { DeleteNextToken(tok);