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

@ -25,7 +25,8 @@
#include <algorithm>
#include <sstream>
#include <fstream>
#include <fstream>
#include <iostream>
#ifdef __BORLANDC__
#include <ctype>
@ -476,7 +477,8 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filename
// std::string line;
std::string path = filename;
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)
{
// 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);
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)
@ -503,7 +514,7 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filename
std::ifstream fin;
fin.open((*iter + filename).c_str());
if (fin.is_open())
{
{
filename = *iter + filename;
processedFile = Preprocessor::read(fin);
break;
@ -516,7 +527,7 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filename
std::ifstream fin(filename.c_str());
processedFile = Preprocessor::read(fin);
}
if (processedFile.length() > 0)
{
// 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
processedFile = removeSpaceNearNL(processedFile);
processedFile = "#file \"" + filename + "\"\n" + processedFile + "\n#endfile";
code.insert(pos, processedFile);
code.insert(pos, processedFile);
}
}
}
}
class Macro
@ -637,9 +649,6 @@ public:
}
};
#include <iostream>
std::string Preprocessor::expandMacros(std::string code)
{
// Search for macros and expand them..