From 8537331ad62388b951e793524b7588fd1f1401bb Mon Sep 17 00:00:00 2001 From: Rikard Falkeborn Date: Thu, 23 Dec 2021 20:09:55 +0100 Subject: [PATCH] AutovarDeallocation: Fix grammar in error message (#3654) --- lib/checkautovariables.cpp | 14 +++++++------- test/testautovariables.cpp | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 15ae03644..50d8e9fec 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -803,16 +803,16 @@ void CheckAutoVariables::errorInvalidDeallocation(const Token *tok, const ValueF { const Variable *var = val ? val->tokvalue->variable() : (tok ? tok->variable() : nullptr); - std::string type = "auto-variable"; + std::string type = "an auto-variable"; if (tok && tok->tokType() == Token::eString) - type = "string literal"; + type = "a string literal"; else if (val && val->tokvalue->tokType() == Token::eString) - type = "pointer pointing to a string literal"; + type = "a pointer pointing to a string literal"; else if (var) { if (var->isGlobal()) - type = "global variable"; + type = "a global variable"; else if (var->isStatic()) - type = "static variable"; + type = "a static variable"; } if (val) @@ -821,7 +821,7 @@ void CheckAutoVariables::errorInvalidDeallocation(const Token *tok, const ValueF reportError(getErrorPath(tok, val, "Deallocating memory that was not dynamically allocated"), Severity::error, "autovarInvalidDeallocation", - "Deallocation of an " + type + " results in undefined behaviour.\n" - "The deallocation of an " + type + " results in undefined behaviour. You should only free memory " + "Deallocation of " + type + " results in undefined behaviour.\n" + "The deallocation of " + type + " results in undefined behaviour. You should only free memory " "that has been allocated dynamically.", CWE590, Certainty::normal); } diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index fd1a10dfc..5d362eb76 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -646,14 +646,14 @@ private: " char *p = tmp1;\n" " free(p);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Deallocation of an static variable (tmp1) results in undefined behaviour.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (error) Deallocation of a static variable (tmp1) results in undefined behaviour.\n", errout.str()); check("char tmp1[256];\n" "void func1() {\n" " char *p; if (x) p = tmp1;\n" " free(p);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Deallocation of an global variable (tmp1) results in undefined behaviour.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (error) Deallocation of a global variable (tmp1) results in undefined behaviour.\n", errout.str()); check("void f()\n" "{\n" @@ -804,11 +804,11 @@ private: " p = \"abc\";\n" " free(p);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Deallocation of an string literal results in undefined behaviour.\n" - "[test.cpp:4]: (error) Deallocation of an string literal results in undefined behaviour.\n" - "[test.cpp:5]: (error) Deallocation of an pointer pointing to a string literal (\"a\") results in undefined behaviour.\n" - "[test.cpp:6]: (error) Deallocation of an pointer pointing to a string literal (\"a\") results in undefined behaviour.\n" - "[test.cpp:9]: (error) Deallocation of an pointer pointing to a string literal (\"abc\") results in undefined behaviour.\n", + ASSERT_EQUALS("[test.cpp:3]: (error) Deallocation of a string literal results in undefined behaviour.\n" + "[test.cpp:4]: (error) Deallocation of a string literal results in undefined behaviour.\n" + "[test.cpp:5]: (error) Deallocation of a pointer pointing to a string literal (\"a\") results in undefined behaviour.\n" + "[test.cpp:6]: (error) Deallocation of a pointer pointing to a string literal (\"a\") results in undefined behaviour.\n" + "[test.cpp:9]: (error) Deallocation of a pointer pointing to a string literal (\"abc\") results in undefined behaviour.\n", errout.str()); check("void f() {\n"