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 "Tokenize.h"
|
||||
#include "tokenize.h"
|
||||
#include "CommonCheck.h"
|
||||
|
||||
#include <sstream>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//---------------------------------------------------------------------------
|
||||
#include "CheckClass.h"
|
||||
#include "Tokenize.h"
|
||||
#include "tokenize.h"
|
||||
#include "CommonCheck.h"
|
||||
#include <locale>
|
||||
#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)
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//---------------------------------------------------------------------------
|
||||
#include "CheckHeaders.h"
|
||||
#include "Tokenize.h"
|
||||
#include "tokenize.h"
|
||||
#include "CommonCheck.h"
|
||||
#include <list>
|
||||
#include <sstream>
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -9,7 +9,11 @@
|
|||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
#ifdef __linux__
|
||||
#include <string.h>
|
||||
#else
|
||||
#include <mem.h> // <- memset
|
||||
#endif
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
@ -24,6 +28,7 @@ struct _variable
|
|||
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Checks for memory leaks inside function..
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//---------------------------------------------------------------------------
|
||||
#include "CheckOther.h"
|
||||
#include "Tokenize.h"
|
||||
#include "tokenize.h"
|
||||
#include "CommonCheck.h"
|
||||
#include <list>
|
||||
#include <sstream>
|
||||
|
@ -249,7 +249,7 @@ void WarningIf()
|
|||
{
|
||||
if (!newstatement || strcmp(tok->str,"if"))
|
||||
{
|
||||
newstatement = (strchr("{};",tok->str[0]) != NULL);
|
||||
newstatement = (strchr("{};",tok->str[0]));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
15
Makefile
15
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
|
||||
|
|
|
@ -114,7 +114,7 @@ Item0=_DEBUG
|
|||
DebugSourceDirs=$(BCB)\source\vcl
|
||||
|
||||
[Parameters]
|
||||
RunParams=testbufferoverrun5\testbufferoverrun5.cpp
|
||||
RunParams=-w testif5\testif5.cpp
|
||||
Launcher=
|
||||
UseLauncher=0
|
||||
DebugCWD=
|
||||
|
|
14
main.cpp
14
main.cpp
|
@ -6,7 +6,7 @@
|
|||
#include <sstream>
|
||||
|
||||
#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
|
||||
|
|
|
@ -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 <stdlib.h> // <- strtoul
|
||||
#include <stdio.h>
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue