Restore severity for 'autoVariables'
This commit is contained in:
parent
0cb45b1f42
commit
92485245ce
|
@ -339,14 +339,14 @@ void CheckAutoVariables::errorReturnPointerToLocalArray(const Token *tok)
|
||||||
void CheckAutoVariables::errorAutoVariableAssignment(const Token *tok, bool inconclusive)
|
void CheckAutoVariables::errorAutoVariableAssignment(const Token *tok, bool inconclusive)
|
||||||
{
|
{
|
||||||
if (!inconclusive) {
|
if (!inconclusive) {
|
||||||
reportError(tok, Severity::warning, "autoVariables",
|
reportError(tok, Severity::error, "autoVariables",
|
||||||
"Address of local auto-variable assigned to a function parameter.\n"
|
"Address of local auto-variable assigned to a function parameter.\n"
|
||||||
"Dangerous assignment - the function parameter is assigned the address of a local "
|
"Dangerous assignment - the function parameter is assigned the address of a local "
|
||||||
"auto-variable. Local auto-variables are reserved from the stack which "
|
"auto-variable. Local auto-variables are reserved from the stack which "
|
||||||
"is freed when the function ends. So the pointer to a local variable "
|
"is freed when the function ends. So the pointer to a local variable "
|
||||||
"is invalid after the function ends.", CWE562, false);
|
"is invalid after the function ends.", CWE562, false);
|
||||||
} else {
|
} else {
|
||||||
reportError(tok, Severity::warning, "autoVariables",
|
reportError(tok, Severity::error, "autoVariables",
|
||||||
"Address of local auto-variable assigned to a function parameter.\n"
|
"Address of local auto-variable assigned to a function parameter.\n"
|
||||||
"Function parameter is assigned the address of a local auto-variable. "
|
"Function parameter is assigned the address of a local auto-variable. "
|
||||||
"Local auto-variables are reserved from the stack which is freed when "
|
"Local auto-variables are reserved from the stack which is freed when "
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
[samples\autoVariables\bad.c:4]: (warning) Address of local auto-variable assigned to a function parameter.
|
[samples\autoVariables\bad.c:4]: (error) Address of local auto-variable assigned to a function parameter.
|
||||||
|
|
|
@ -133,7 +133,7 @@ private:
|
||||||
" int num = 2;\n"
|
" int num = 2;\n"
|
||||||
" *res = #\n"
|
" *res = #\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (warning) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
||||||
|
|
||||||
check("void func1(int **res)\n"
|
check("void func1(int **res)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -159,7 +159,7 @@ private:
|
||||||
" int num = 2;\n"
|
" int num = 2;\n"
|
||||||
" *res = #\n"
|
" *res = #\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (warning) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
||||||
|
|
||||||
check("class Fred {\n"
|
check("class Fred {\n"
|
||||||
" void func1(int **res);\n"
|
" void func1(int **res);\n"
|
||||||
|
@ -188,7 +188,7 @@ private:
|
||||||
" int x[100];\n"
|
" int x[100];\n"
|
||||||
" *p = x;\n"
|
" *p = x;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (warning) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testautovar4() { // ticket #2928
|
void testautovar4() { // ticket #2928
|
||||||
|
@ -206,7 +206,7 @@ private:
|
||||||
" char a;\n"
|
" char a;\n"
|
||||||
" ab->a = &a;\n"
|
" ab->a = &a;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (warning) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testautovar6() { // ticket #2931
|
void testautovar6() { // ticket #2931
|
||||||
|
@ -222,7 +222,7 @@ private:
|
||||||
" char a[10];\n"
|
" char a[10];\n"
|
||||||
" x->str = a;\n"
|
" x->str = a;\n"
|
||||||
"}", true);
|
"}", true);
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testautovar7() { // ticket #3066
|
void testautovar7() { // ticket #3066
|
||||||
|
@ -240,7 +240,7 @@ private:
|
||||||
" int i = 0;\n"
|
" int i = 0;\n"
|
||||||
" p = &i;\n"
|
" p = &i;\n"
|
||||||
"}", false);
|
"}", false);
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
||||||
|
|
||||||
check("void foo(std::string& s) {\n"
|
check("void foo(std::string& s) {\n"
|
||||||
" s = foo;\n"
|
" s = foo;\n"
|
||||||
|
@ -258,7 +258,7 @@ private:
|
||||||
" p = &p_fp->i;\n"
|
" p = &p_fp->i;\n"
|
||||||
" p = &fp.f->i;\n"
|
" p = &fp.f->i;\n"
|
||||||
"}", false);
|
"}", false);
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (warning) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testautovar10() { // #2930 - assignment of function parameter
|
void testautovar10() { // #2930 - assignment of function parameter
|
||||||
|
@ -371,7 +371,7 @@ private:
|
||||||
" struct A a = bar();\n"
|
" struct A a = bar();\n"
|
||||||
" *p = &a.data[0];\n"
|
" *p = &a.data[0];\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (warning) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
||||||
|
|
||||||
check("void f(char **out) {\n"
|
check("void f(char **out) {\n"
|
||||||
" struct S *p = glob;\n"
|
" struct S *p = glob;\n"
|
||||||
|
@ -390,7 +390,7 @@ private:
|
||||||
" s8 p[10];\n" // <- p is array => error
|
" s8 p[10];\n" // <- p is array => error
|
||||||
" *out = &p[1];\n"
|
" *out = &p[1];\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testautovar12() { // Ticket #5024, #5050 - Crash on invalid input
|
void testautovar12() { // Ticket #5024, #5050 - Crash on invalid input
|
||||||
|
@ -450,7 +450,7 @@ private:
|
||||||
" int num=2;"
|
" int num=2;"
|
||||||
" arr[0]=#\n"
|
" arr[0]=#\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testautovar_array2() {
|
void testautovar_array2() {
|
||||||
|
@ -462,7 +462,7 @@ private:
|
||||||
" int num=2;"
|
" int num=2;"
|
||||||
" arr[0]=#\n"
|
" arr[0]=#\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (warning) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testautovar_normal() {
|
void testautovar_normal() {
|
||||||
|
@ -471,7 +471,7 @@ private:
|
||||||
" XPoint DropPoint;\n"
|
" XPoint DropPoint;\n"
|
||||||
" ds->location_data = (XtPointer *)&DropPoint;\n"
|
" ds->location_data = (XtPointer *)&DropPoint;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (warning) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testautovar_ptrptr() { // #6596
|
void testautovar_ptrptr() { // #6596
|
||||||
|
@ -479,7 +479,7 @@ private:
|
||||||
" char dead_slot;\n"
|
" char dead_slot;\n"
|
||||||
" matches[0] = (char *)&dead_slot;\n"
|
" matches[0] = (char *)&dead_slot;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testautovar_return1() {
|
void testautovar_return1() {
|
||||||
|
|
Loading…
Reference in New Issue