AutovarDeallocation: Fix grammar in error message (#3654)

This commit is contained in:
Rikard Falkeborn 2021-12-23 20:09:55 +01:00 committed by GitHub
parent d36aa590cd
commit 8537331ad6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 14 deletions

View File

@ -803,16 +803,16 @@ void CheckAutoVariables::errorInvalidDeallocation(const Token *tok, const ValueF
{ {
const Variable *var = val ? val->tokvalue->variable() : (tok ? tok->variable() : nullptr); 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) if (tok && tok->tokType() == Token::eString)
type = "string literal"; type = "a string literal";
else if (val && val->tokvalue->tokType() == Token::eString) 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) { else if (var) {
if (var->isGlobal()) if (var->isGlobal())
type = "global variable"; type = "a global variable";
else if (var->isStatic()) else if (var->isStatic())
type = "static variable"; type = "a static variable";
} }
if (val) 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"), reportError(getErrorPath(tok, val, "Deallocating memory that was not dynamically allocated"),
Severity::error, Severity::error,
"autovarInvalidDeallocation", "autovarInvalidDeallocation",
"Deallocation of an " + type + " results in undefined behaviour.\n" "Deallocation of " + type + " results in undefined behaviour.\n"
"The deallocation of an " + type + " results in undefined behaviour. You should only free memory " "The deallocation of " + type + " results in undefined behaviour. You should only free memory "
"that has been allocated dynamically.", CWE590, Certainty::normal); "that has been allocated dynamically.", CWE590, Certainty::normal);
} }

View File

@ -646,14 +646,14 @@ private:
" char *p = tmp1;\n" " char *p = tmp1;\n"
" free(p);\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" check("char tmp1[256];\n"
"void func1() {\n" "void func1() {\n"
" char *p; if (x) p = tmp1;\n" " char *p; if (x) p = tmp1;\n"
" free(p);\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" check("void f()\n"
"{\n" "{\n"
@ -804,11 +804,11 @@ private:
" p = \"abc\";\n" " p = \"abc\";\n"
" free(p);\n" " free(p);\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Deallocation of an string literal 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 an 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 an pointer pointing to a string literal (\"a\") 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 an 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 an pointer pointing to a string literal (\"abc\") 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()); errout.str());
check("void f() {\n" check("void f() {\n"