From 9a102702cbf5d643dee70abc03e0af51008be8b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 6 Jan 2012 16:08:08 +0100 Subject: [PATCH] Refactoring: Disable debug warnings when file extension is neither .c nor .cpp. To somewhat prevent that people fix java/c# specific debug warnings. --- lib/cppcheck.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 624df01178f..fb88315e0be 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -138,10 +138,26 @@ bool CppCheck::findError(std::string code, const char FileName[]) return true; } +// Disable debug warnings? +static bool no_debug_warnings(const std::string &filename) { + const std::string::size_type pos = filename.rfind("."); + if (pos == std::string::npos) + return false; + const std::string ext = filename.substr(pos); + + // Only allow debug warnings if file extension is c or cpp so people + // won't be tempted to fix java / c# problems spotted this way. + return bool(ext != ".c" && ext != ".cpp"); +} + unsigned int CppCheck::processFile() { exitcode = 0; + // disable debug warnings? + if (no_debug_warnings(_filename)) + _settings.debugwarnings = false; + // TODO: Should this be moved out to its own function so all the files can be // analysed before any files are checked? if (_settings.test_2_pass && _settings._jobs == 1) {