From 6874f27e73f6af34ebaf41b88e41a55cd58e022c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 26 Mar 2017 11:23:39 +0200 Subject: [PATCH] Added CHECK_WRONG_DATA() that can be used to avoid crashes/hangs in release binaries --- lib/check.h | 7 +++++++ lib/checkfunctions.cpp | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/check.h b/lib/check.h index 7d0c35776..6bb711a11 100644 --- a/lib/check.h +++ b/lib/check.h @@ -30,6 +30,13 @@ #include #include +/** + * Use this macro Cppcheck data can be wrong and you need a to check if that happens to avoid crash/hang + * Using this macro we can make sure that released binaries don't crash/hang but the problem is not hidden + * in debug builds. + */ +#define CHECK_WRONG_DATA(X) (X) + /// @addtogroup Core /// @{ diff --git a/lib/checkfunctions.cpp b/lib/checkfunctions.cpp index d325e8fa0..364bf919a 100644 --- a/lib/checkfunctions.cpp +++ b/lib/checkfunctions.cpp @@ -175,7 +175,7 @@ void CheckFunctions::checkIgnoredReturnValue() while (parent->astParent() && parent->astParent()->str() == "::") parent = parent->astParent(); - if (!tok->next()->astParent() && (!tok->function() || !Token::Match(tok->function()->retDef, "void %name%")) && _settings->library.isUseRetVal(tok)) + if (CHECK_WRONG_DATA(tok->next()->astOperand1()) && !tok->next()->astParent() && (!tok->function() || !Token::Match(tok->function()->retDef, "void %name%")) && _settings->library.isUseRetVal(tok)) ignoredReturnValueError(tok, tok->next()->astOperand1()->expressionString()); } }