Fixed Ticket #52, Cppcheck hangs when checking VLC's source code

This commit is contained in:
Reijo Tomperi 2009-01-23 18:27:04 +00:00
parent 193cffdb0b
commit 6a523f2730
2 changed files with 20 additions and 10 deletions

View File

@ -408,4 +408,5 @@ void CppCheck::reportOut(const std::string &outmsg)
{
// This is currently never called. It is here just to comply with
// the interface.
std::string foo = outmsg; // This is just to get rid of compiler warning
}

View File

@ -26,6 +26,7 @@
#include <sstream>
#include <fstream>
#include <iostream>
#ifdef __BORLANDC__
#include <ctype>
@ -477,6 +478,7 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filename
std::string path = filename;
path.erase(1 + path.find_last_of("\\/"));
std::string::size_type pos = 0;
std::map<std::string,bool> handledFiles;
while ((pos = code.find("#include", pos)) != std::string::npos)
{
// Accept only includes that are at the start of a line
@ -496,6 +498,15 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filename
if (filename.length() == 0)
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"
std::string processedFile;
for (std::list<std::string>::const_iterator iter = includePaths.begin(); iter != includePaths.end(); ++iter)
@ -530,6 +541,7 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filename
processedFile = removeSpaceNearNL(processedFile);
processedFile = "#file \"" + filename + "\"\n" + processedFile + "\n#endfile";
code.insert(pos, processedFile);
}
}
}
@ -637,9 +649,6 @@ public:
}
};
#include <iostream>
std::string Preprocessor::expandMacros(std::string code)
{
// Search for macros and expand them..