Minor updates to make it portable to Linux.
This commit is contained in:
parent
b0d9994210
commit
ba13ad5e3c
|
@ -1,6 +1,6 @@
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
#include "CheckBufferOverrun.h"
|
#include "CheckBufferOverrun.h"
|
||||||
#include "Tokenize.h"
|
#include "tokenize.h"
|
||||||
#include "CommonCheck.h"
|
#include "CommonCheck.h"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
#include "CheckClass.h"
|
#include "CheckClass.h"
|
||||||
#include "Tokenize.h"
|
#include "tokenize.h"
|
||||||
#include "CommonCheck.h"
|
#include "CommonCheck.h"
|
||||||
#include <locale>
|
#include <locale>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
@ -181,7 +181,11 @@ static TOKEN * ClassChecking_VarList_RemoveAssigned(TOKEN *_tokens, struct VAR *
|
||||||
if (strcmp(ftok->next->str,".")==0 || strcmp(ftok->next->str,"->")==0)
|
if (strcmp(ftok->next->str,".")==0 || strcmp(ftok->next->str,"->")==0)
|
||||||
{
|
{
|
||||||
// The functions 'clear' and 'Clear' are supposed to initialize variable.
|
// 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)
|
if (stricmp(ftok->next->next->str,"clear") == 0)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
for (struct VAR *var = varlist; var; var = var->next)
|
for (struct VAR *var = varlist; var; var = var->next)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
#include "CheckHeaders.h"
|
#include "CheckHeaders.h"
|
||||||
#include "Tokenize.h"
|
#include "tokenize.h"
|
||||||
#include "CommonCheck.h"
|
#include "CommonCheck.h"
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -61,7 +61,11 @@ void WarningIncludeHeader()
|
||||||
const char *includefile = includetok->next->str;
|
const char *includefile = includetok->next->str;
|
||||||
while (hfile < Files.size())
|
while (hfile < Files.size())
|
||||||
{
|
{
|
||||||
|
#ifdef __linux__
|
||||||
|
if (strcasecmp(Files[hfile].c_str(), includefile) == 0)
|
||||||
|
#else
|
||||||
if (stricmp(Files[hfile].c_str(), includefile) == 0)
|
if (stricmp(Files[hfile].c_str(), includefile) == 0)
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
hfile++;
|
hfile++;
|
||||||
}
|
}
|
||||||
|
@ -90,21 +94,14 @@ void WarningIncludeHeader()
|
||||||
indentlevel++;
|
indentlevel++;
|
||||||
|
|
||||||
else if (tok1->str[0] == '}')
|
else if (tok1->str[0] == '}')
|
||||||
{
|
|
||||||
if (indentlevel > 0)
|
|
||||||
indentlevel--;
|
indentlevel--;
|
||||||
}
|
|
||||||
|
|
||||||
if (indentlevel != 0)
|
if (indentlevel != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// namespace..
|
|
||||||
if (match(tok1,"namespace var {"))
|
|
||||||
tok1 = gettok(tok1,2);
|
|
||||||
|
|
||||||
// Class or namespace declaration..
|
// 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));
|
classlist.push_back(getstr(tok1, 1));
|
||||||
|
|
||||||
// Variable declaration..
|
// Variable declaration..
|
||||||
|
@ -206,21 +203,7 @@ void WarningIncludeHeader()
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! NeedDeclaration )
|
if ( ! NeedDeclaration )
|
||||||
{
|
NeedDeclaration = (std::find(classlist.begin(),classlist.end(),tok1->str ) != classlist.end());
|
||||||
if (std::find(classlist.begin(),classlist.end(),tok1->str ) != classlist.end())
|
|
||||||
{
|
|
||||||
if ( strcmp(getstr(tok1, 1), "*") == 0 )
|
|
||||||
{
|
|
||||||
NeedDeclaration = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Needed = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,11 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
#include <string.h>
|
||||||
|
#else
|
||||||
#include <mem.h> // <- memset
|
#include <mem.h> // <- memset
|
||||||
|
#endif
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -24,6 +28,7 @@ struct _variable
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
// Checks for memory leaks inside function..
|
// Checks for memory leaks inside function..
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
#include "CheckOther.h"
|
#include "CheckOther.h"
|
||||||
#include "Tokenize.h"
|
#include "tokenize.h"
|
||||||
#include "CommonCheck.h"
|
#include "CommonCheck.h"
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -249,7 +249,7 @@ void WarningIf()
|
||||||
{
|
{
|
||||||
if (!newstatement || strcmp(tok->str,"if"))
|
if (!newstatement || strcmp(tok->str,"if"))
|
||||||
{
|
{
|
||||||
newstatement = (strchr("{};",tok->str[0]) != NULL);
|
newstatement = (strchr("{};",tok->str[0]));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
Makefile
13
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)
|
||||||
|
|
||||||
|
|
||||||
all:
|
%.o: %.cpp
|
||||||
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 -I. -o $@ -c $^
|
||||||
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
|
||||||
|
|
|
@ -114,7 +114,7 @@ Item0=_DEBUG
|
||||||
DebugSourceDirs=$(BCB)\source\vcl
|
DebugSourceDirs=$(BCB)\source\vcl
|
||||||
|
|
||||||
[Parameters]
|
[Parameters]
|
||||||
RunParams=testbufferoverrun5\testbufferoverrun5.cpp
|
RunParams=-w testif5\testif5.cpp
|
||||||
Launcher=
|
Launcher=
|
||||||
UseLauncher=0
|
UseLauncher=0
|
||||||
DebugCWD=
|
DebugCWD=
|
||||||
|
|
14
main.cpp
14
main.cpp
|
@ -6,7 +6,7 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "tokenize.h" // <- Tokenizer
|
#include "tokenize.h" // <- Tokenizer
|
||||||
#include "statements.h" // <- Statement list
|
#include "Statements.h" // <- Statement list
|
||||||
|
|
||||||
#include "CheckMemoryLeak.h"
|
#include "CheckMemoryLeak.h"
|
||||||
#include "CheckBufferOverrun.h"
|
#include "CheckBufferOverrun.h"
|
||||||
|
@ -31,10 +31,18 @@ int main(int argc, char* argv[])
|
||||||
const char *fname = NULL;
|
const char *fname = NULL;
|
||||||
for (int i = 1; i < argc; i++)
|
for (int i = 1; i < argc; i++)
|
||||||
{
|
{
|
||||||
|
#ifdef __linux__
|
||||||
|
if(strcasecmp(argv[i],"--debug") == 0)
|
||||||
|
#else
|
||||||
if (stricmp(argv[i],"--debug") == 0)
|
if (stricmp(argv[i],"--debug") == 0)
|
||||||
|
#endif
|
||||||
Debug = true;
|
Debug = true;
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
else if (strcasecmp(argv[i],"-w") == 0)
|
||||||
|
#else
|
||||||
else if (stricmp(argv[i],"-w") == 0)
|
else if (stricmp(argv[i],"-w") == 0)
|
||||||
|
#endif
|
||||||
ShowWarnings = true;
|
ShowWarnings = true;
|
||||||
|
|
||||||
else
|
else
|
||||||
|
@ -105,7 +113,11 @@ static void CppCheck(const char FileName[])
|
||||||
|
|
||||||
// Warning upon c-style pointer casts
|
// Warning upon c-style pointer casts
|
||||||
const char *ext = strrchr(FileName, '.');
|
const char *ext = strrchr(FileName, '.');
|
||||||
|
#ifdef __linux__
|
||||||
|
if (ext && strcasecmp(ext,".c"))
|
||||||
|
#else
|
||||||
if (ext && stricmp(ext,".c"))
|
if (ext && stricmp(ext,".c"))
|
||||||
|
#endif
|
||||||
WarningOldStylePointerCast();
|
WarningOldStylePointerCast();
|
||||||
|
|
||||||
// Use standard functions instead
|
// Use standard functions instead
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
|
||||||
|
|
||||||
|
class clKalle
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
int i;
|
||||||
|
public:
|
||||||
|
clKalle();
|
||||||
|
};
|
||||||
|
|
||||||
|
clKalle::clKalle()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
24
tokenize.cpp
24
tokenize.cpp
|
@ -10,6 +10,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <stdlib.h> // <- strtoul
|
#include <stdlib.h> // <- strtoul
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -75,7 +76,8 @@ static void Define(const char Name[], const char Value[])
|
||||||
char str[50];
|
char str[50];
|
||||||
unsigned long value = strtoul(Value+2, NULL, 16);
|
unsigned long value = strtoul(Value+2, NULL, 16);
|
||||||
free(strValue);
|
free(strValue);
|
||||||
strValue = strdup(itoa(value, str, 10));
|
sprintf(str, "%d", value);
|
||||||
|
strValue = strdup(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
DefineSymbol *NewSym = new DefineSymbol;
|
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)
|
if (strncmp(str,"0x",2)==0)
|
||||||
{
|
{
|
||||||
unsigned int value = strtoul(str+2, NULL, 16);
|
unsigned int value = strtoul(str+2, NULL, 16);
|
||||||
itoa(value, str2, 10);
|
sprintf( str2, "%d", value );
|
||||||
}
|
}
|
||||||
|
|
||||||
TOKEN *newtoken = new TOKEN;
|
TOKEN *newtoken = new TOKEN;
|
||||||
|
@ -248,7 +250,11 @@ void Tokenize(const char FileName[])
|
||||||
// Has this file been tokenized already?
|
// Has this file been tokenized already?
|
||||||
for (unsigned int i = 0; i < Files.size(); i++)
|
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 )
|
if ( stricmp(Files[i].c_str(), FileName) == 0 )
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -668,7 +674,8 @@ void SimplifyTokenList()
|
||||||
free(tok->str);
|
free(tok->str);
|
||||||
char str[10];
|
char str[10];
|
||||||
// 'sizeof(type *)' has the same size as 'sizeof(char *)'
|
// '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++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
|
@ -684,8 +691,8 @@ void SimplifyTokenList()
|
||||||
{
|
{
|
||||||
free(tok->str);
|
free(tok->str);
|
||||||
char str[10];
|
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++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
DeleteNextToken(tok);
|
DeleteNextToken(tok);
|
||||||
|
@ -730,8 +737,8 @@ void SimplifyTokenList()
|
||||||
{
|
{
|
||||||
free(tok2->str);
|
free(tok2->str);
|
||||||
char str[20];
|
char str[20];
|
||||||
tok2->str = strdup(itoa(total_size, str, 10));
|
sprintf( str, "%d", total_size);
|
||||||
|
tok2->str = strdup(str );
|
||||||
// Delete the other tokens..
|
// Delete the other tokens..
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
|
@ -782,7 +789,8 @@ void SimplifyTokenList()
|
||||||
tok = tok->next;
|
tok = tok->next;
|
||||||
free(tok->str);
|
free(tok->str);
|
||||||
char str[10];
|
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++)
|
for (int i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
DeleteNextToken(tok);
|
DeleteNextToken(tok);
|
||||||
|
|
Loading…
Reference in New Issue