Do not warn about alloca() in C89 mode (#7558)
This commit is contained in:
parent
721bc32b2d
commit
dde6f5eaea
|
@ -48,13 +48,14 @@ void CheckFunctions::checkProhibitedFunctions()
|
||||||
if (tok->isName() && tok->varId() == 0 && tok->strAt(1) == "(") {
|
if (tok->isName() && tok->varId() == 0 && tok->strAt(1) == "(") {
|
||||||
// alloca() is special as it depends on the code being C or C++, so it is not in Library
|
// alloca() is special as it depends on the code being C or C++, so it is not in Library
|
||||||
if (checkAlloca && Token::simpleMatch(tok, "alloca (") && (!tok->function() || tok->function()->nestedIn->type == Scope::eGlobal)) {
|
if (checkAlloca && Token::simpleMatch(tok, "alloca (") && (!tok->function() || tok->function()->nestedIn->type == Scope::eGlobal)) {
|
||||||
if (_tokenizer->isC())
|
if (_tokenizer->isC()) {
|
||||||
reportError(tok, Severity::warning, "allocaCalled",
|
if (_settings->standards.c > Standards::C89)
|
||||||
"Obsolete function 'alloca' called. In C99 and later it is recommended to use a variable length array instead.\n"
|
reportError(tok, Severity::warning, "allocaCalled",
|
||||||
"The obsolete function 'alloca' is called. In C99 and later it is recommended to use a variable length array or "
|
"Obsolete function 'alloca' called. In C99 and later it is recommended to use a variable length array instead.\n"
|
||||||
"a dynamically allocated array instead. The function 'alloca' is dangerous for many reasons "
|
"The obsolete function 'alloca' is called. In C99 and later it is recommended to use a variable length array or "
|
||||||
"(http://stackoverflow.com/questions/1018853/why-is-alloca-not-considered-good-practice and http://linux.die.net/man/3/alloca).");
|
"a dynamically allocated array instead. The function 'alloca' is dangerous for many reasons "
|
||||||
else
|
"(http://stackoverflow.com/questions/1018853/why-is-alloca-not-considered-good-practice and http://linux.die.net/man/3/alloca).");
|
||||||
|
} else
|
||||||
reportError(tok, Severity::warning, "allocaCalled",
|
reportError(tok, Severity::warning, "allocaCalled",
|
||||||
"Obsolete function 'alloca' called.\n"
|
"Obsolete function 'alloca' called.\n"
|
||||||
"The obsolete function 'alloca' is called. In C++11 and later it is recommended to use std::array<> or "
|
"The obsolete function 'alloca' is called. In C++11 and later it is recommended to use std::array<> or "
|
||||||
|
|
|
@ -246,6 +246,12 @@ private:
|
||||||
"}", "test.cpp"); // #4382 - there are no VLAs in C++
|
"}", "test.cpp"); // #4382 - there are no VLAs in C++
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void f()\n"
|
||||||
|
"{\n"
|
||||||
|
" char *x = alloca(10);\n"
|
||||||
|
"}", "test.c"); // #7558 - no alternative to alloca in C89
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" char *x = alloca(10);\n"
|
" char *x = alloca(10);\n"
|
||||||
|
|
Loading…
Reference in New Issue