Fixed 188 (Return of auto variable address), applied patched submitted by gscacco
This commit is contained in:
parent
da06c12925
commit
729b2c1706
4
Makefile
4
Makefile
|
@ -32,6 +32,7 @@ TESTOBJ = test/testbufferoverrun.o \
|
||||||
test/testconstructors.o \
|
test/testconstructors.o \
|
||||||
test/testcppcheck.o \
|
test/testcppcheck.o \
|
||||||
test/testdangerousfunctions.o \
|
test/testdangerousfunctions.o \
|
||||||
|
test/testautovariables.o \
|
||||||
test/testdivision.o \
|
test/testdivision.o \
|
||||||
test/testfilelister.o \
|
test/testfilelister.o \
|
||||||
test/testfunctionusage.o \
|
test/testfunctionusage.o \
|
||||||
|
@ -180,6 +181,9 @@ test/testcppcheck.o: test/testcppcheck.cpp test/testsuite.h src/errorlogger.h sr
|
||||||
test/testdangerousfunctions.o: test/testdangerousfunctions.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/checkdangerousfunctions.h src/check.h test/testsuite.h
|
test/testdangerousfunctions.o: test/testdangerousfunctions.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/checkdangerousfunctions.h src/check.h test/testsuite.h
|
||||||
$(CXX) $(CXXFLAGS) -c -o test/testdangerousfunctions.o test/testdangerousfunctions.cpp
|
$(CXX) $(CXXFLAGS) -c -o test/testdangerousfunctions.o test/testdangerousfunctions.cpp
|
||||||
|
|
||||||
|
test/testautovariables.o: test/testautovariables.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/checkdangerousfunctions.h src/check.h test/testsuite.h
|
||||||
|
$(CXX) $(CXXFLAGS) -c -o test/testautovariables.o test/testautovariables.cpp
|
||||||
|
|
||||||
test/testdivision.o: test/testdivision.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/checkother.h src/check.h test/testsuite.h
|
test/testdivision.o: test/testdivision.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/checkother.h src/check.h test/testsuite.h
|
||||||
$(CXX) $(CXXFLAGS) -c -o test/testdivision.o test/testdivision.cpp
|
$(CXX) $(CXXFLAGS) -c -o test/testdivision.o test/testdivision.cpp
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Cppcheck - A tool for static C/C++ code analysis
|
* Cppcheck - A tool for static C/C++ code analysis
|
||||||
* Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam,
|
* Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam,
|
||||||
* Leandro Penz, Kimmo Varis, Vesa Pikki
|
* Leandro Penz, Kimmo Varis, Vesa Pikki, Gianluca Scacco
|
||||||
*
|
*
|
||||||
* 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
|
||||||
|
@ -111,11 +111,26 @@ bool isTypeName(const Token *tok)
|
||||||
ret |= (_str == type[i]);
|
ret |= (_str == type[i]);
|
||||||
return !ret;
|
return !ret;
|
||||||
}
|
}
|
||||||
|
bool isStatic(const Token *tok)
|
||||||
|
{
|
||||||
|
bool res = false;
|
||||||
|
|
||||||
|
if (Token::Match(tok->tokAt(-1), "static "))
|
||||||
|
res = true;
|
||||||
|
else if (Token::Match(tok->tokAt(-2), "static "))
|
||||||
|
res = true;
|
||||||
|
else if (Token::Match(tok->tokAt(-3), "static "))
|
||||||
|
res = true;
|
||||||
|
|
||||||
|
//std::cout << __PRETTY_FUNCTION__ << " " << tok->str() << " " << res << std::endl;
|
||||||
|
return res;
|
||||||
|
|
||||||
|
}
|
||||||
void CheckAutoVariables::addVD(const Token* tok)
|
void CheckAutoVariables::addVD(const Token* tok)
|
||||||
{
|
{
|
||||||
std::string var_name;
|
std::string var_name;
|
||||||
var_name = tok->str();
|
var_name = tok->str();
|
||||||
//cout << "VD " << tok->linenr() << " " << var_name << endl;
|
//std::cout << "VD " << tok->linenr() << " " << var_name << std::endl;
|
||||||
vd_list.push_back(var_name);
|
vd_list.push_back(var_name);
|
||||||
}
|
}
|
||||||
void CheckAutoVariables::autoVariables()
|
void CheckAutoVariables::autoVariables()
|
||||||
|
@ -155,20 +170,17 @@ void CheckAutoVariables::autoVariables()
|
||||||
{
|
{
|
||||||
bindent--;
|
bindent--;
|
||||||
}
|
}
|
||||||
else if (bindent > 0 && Token::Match(tok, "%type% :: %any%")) //Inside a function
|
else if (bindent > 0 && Token::Match(tok, "%type% :: %any%") && !isStatic(tok)) //Inside a function
|
||||||
{
|
{
|
||||||
std::string var_name;
|
addVD(tok->tokAt(2));
|
||||||
//print(tok,5);
|
|
||||||
var_name = tok->tokAt(2)->str();
|
|
||||||
vd_list.push_back(var_name);
|
|
||||||
}
|
}
|
||||||
else if (bindent > 0 && Token::Match(tok, "%var% %var% ;")) //Inside a function
|
else if (bindent > 0 && Token::Match(tok, "%var% %var% ;") && !isStatic(tok)) //Inside a function
|
||||||
{
|
{
|
||||||
if (!isTypeName(tok))
|
if (!isTypeName(tok))
|
||||||
continue;
|
continue;
|
||||||
addVD(tok->tokAt(1));
|
addVD(tok->tokAt(1));
|
||||||
}
|
}
|
||||||
else if (bindent > 0 && Token::Match(tok, "const %var% %var% ;")) //Inside a function
|
else if (bindent > 0 && Token::Match(tok, "const %var% %var% ;") && !isStatic(tok)) //Inside a function
|
||||||
{
|
{
|
||||||
if (!isTypeName(tok->tokAt(1)))
|
if (!isTypeName(tok->tokAt(1)))
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue