From 761dd419afb5af06c91c8d6b34f2751c0609c281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 1 May 2011 12:59:08 +0200 Subject: [PATCH] Fixed #2719 (Fix excessive false positives in include-file handling) --- lib/preprocessor.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index de87dd825..e4235dd00 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -1971,9 +1971,28 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath } } +static bool missingIncludes[256]; + // Report that include is missing void Preprocessor::missingInclude(const std::string &filename, unsigned int linenr, const std::string &header, bool userheader) { + // FIXME: we need to check if this is a duplicate error. has it + // been reported already that this header is missing? This is not + // a trivial task because it must be thread safe and the code in the + // lib must be plain C++. + + // A simple solution is to calculate a sum of the header name, + // if the same sum has been used before then bailout + { + unsigned char sum = 0; + for (unsigned int i = 0; i < header.size(); ++i) + sum += header[i]; + + if (missingIncludes[sum]) + return; + missingIncludes[sum] = 1; + } + std::list locationList; if (!filename.empty()) {