From 6770cc80be6b0eba5cd45bcf786687f3b25e9bd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 28 Dec 2012 11:42:50 +0100 Subject: [PATCH] Uninitialized variables: Added debug warning for bailout --- lib/checkuninitvar.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 0df211fe6..e56d2cc1e 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1174,8 +1174,18 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok, // if (a) x=0; // conditional initialization // if (b) return; // cppcheck doesn't know if b can be false when a is false. // x++; // it's possible x is always initialized - if (!alwaysTrue && noreturnIf && number_of_if > 0) + if (!alwaysTrue && noreturnIf && number_of_if > 0) { + if (_settings->debugwarnings) { + std::string condition; + for (const Token *tok2 = tok->linkAt(-1); tok2 != tok; tok2 = tok2->next()) { + condition += tok2->str(); + if (tok2->isName() && tok2->next()->isName()) + condition += ' '; + } + reportError(tok, Severity::debug, "debug", "uninitialized variables: bailout. can't determine if this condition can be false when previous condition is false: " + condition); + } return true; + } std::map varValueIf; if (!initif) {