Fixed Ticket #52, Cppcheck hangs when checking VLC's source code
This commit is contained in:
parent
193cffdb0b
commit
6a523f2730
|
@ -408,4 +408,5 @@ void CppCheck::reportOut(const std::string &outmsg)
|
||||||
{
|
{
|
||||||
// This is currently never called. It is here just to comply with
|
// This is currently never called. It is here just to comply with
|
||||||
// the interface.
|
// the interface.
|
||||||
|
std::string foo = outmsg; // This is just to get rid of compiler warning
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,8 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#ifdef __BORLANDC__
|
#ifdef __BORLANDC__
|
||||||
#include <ctype>
|
#include <ctype>
|
||||||
|
@ -476,7 +477,8 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filename
|
||||||
// std::string line;
|
// std::string line;
|
||||||
std::string path = filename;
|
std::string path = filename;
|
||||||
path.erase(1 + path.find_last_of("\\/"));
|
path.erase(1 + path.find_last_of("\\/"));
|
||||||
std::string::size_type pos = 0;
|
std::string::size_type pos = 0;
|
||||||
|
std::map<std::string,bool> handledFiles;
|
||||||
while ((pos = code.find("#include", pos)) != std::string::npos)
|
while ((pos = code.find("#include", pos)) != std::string::npos)
|
||||||
{
|
{
|
||||||
// Accept only includes that are at the start of a line
|
// Accept only includes that are at the start of a line
|
||||||
|
@ -495,7 +497,16 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filename
|
||||||
filename = getHeaderFileName(filename);
|
filename = getHeaderFileName(filename);
|
||||||
if (filename.length() == 0)
|
if (filename.length() == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if( handledFiles.find( filename ) != handledFiles.end() )
|
||||||
|
{
|
||||||
|
// We have processed this file already once, skip
|
||||||
|
// it this time to avoid ethernal loop.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
handledFiles[ filename ] = true;
|
||||||
|
|
||||||
// filename contains now a file name e.g. "menu.h"
|
// filename contains now a file name e.g. "menu.h"
|
||||||
std::string processedFile;
|
std::string processedFile;
|
||||||
for (std::list<std::string>::const_iterator iter = includePaths.begin(); iter != includePaths.end(); ++iter)
|
for (std::list<std::string>::const_iterator iter = includePaths.begin(); iter != includePaths.end(); ++iter)
|
||||||
|
@ -503,7 +514,7 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filename
|
||||||
std::ifstream fin;
|
std::ifstream fin;
|
||||||
fin.open((*iter + filename).c_str());
|
fin.open((*iter + filename).c_str());
|
||||||
if (fin.is_open())
|
if (fin.is_open())
|
||||||
{
|
{
|
||||||
filename = *iter + filename;
|
filename = *iter + filename;
|
||||||
processedFile = Preprocessor::read(fin);
|
processedFile = Preprocessor::read(fin);
|
||||||
break;
|
break;
|
||||||
|
@ -516,7 +527,7 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filename
|
||||||
std::ifstream fin(filename.c_str());
|
std::ifstream fin(filename.c_str());
|
||||||
processedFile = Preprocessor::read(fin);
|
processedFile = Preprocessor::read(fin);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (processedFile.length() > 0)
|
if (processedFile.length() > 0)
|
||||||
{
|
{
|
||||||
// Replace all tabs with spaces..
|
// Replace all tabs with spaces..
|
||||||
|
@ -529,9 +540,10 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filename
|
||||||
// Remove space characters that are after or before new line character
|
// Remove space characters that are after or before new line character
|
||||||
processedFile = removeSpaceNearNL(processedFile);
|
processedFile = removeSpaceNearNL(processedFile);
|
||||||
processedFile = "#file \"" + filename + "\"\n" + processedFile + "\n#endfile";
|
processedFile = "#file \"" + filename + "\"\n" + processedFile + "\n#endfile";
|
||||||
code.insert(pos, processedFile);
|
code.insert(pos, processedFile);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Macro
|
class Macro
|
||||||
|
@ -637,9 +649,6 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
std::string Preprocessor::expandMacros(std::string code)
|
std::string Preprocessor::expandMacros(std::string code)
|
||||||
{
|
{
|
||||||
// Search for macros and expand them..
|
// Search for macros and expand them..
|
||||||
|
|
Loading…
Reference in New Issue