From 92485245cec0721cfcf21bb7fd155e650ae1be6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 15 Mar 2019 15:13:11 +0100 Subject: [PATCH] Restore severity for 'autoVariables' --- lib/checkautovariables.cpp | 4 ++-- samples/autoVariables/out.txt | 2 +- test/testautovariables.cpp | 26 +++++++++++++------------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 3fe603a87..30d6a603c 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -339,14 +339,14 @@ void CheckAutoVariables::errorReturnPointerToLocalArray(const Token *tok) void CheckAutoVariables::errorAutoVariableAssignment(const Token *tok, bool inconclusive) { if (!inconclusive) { - reportError(tok, Severity::warning, "autoVariables", + reportError(tok, Severity::error, "autoVariables", "Address of local auto-variable assigned to a function parameter.\n" "Dangerous assignment - the function parameter is assigned the address of a local " "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 invalid after the function ends.", CWE562, false); } else { - reportError(tok, Severity::warning, "autoVariables", + reportError(tok, Severity::error, "autoVariables", "Address of local auto-variable assigned to a function parameter.\n" "Function parameter is assigned the address of a local auto-variable. " "Local auto-variables are reserved from the stack which is freed when " diff --git a/samples/autoVariables/out.txt b/samples/autoVariables/out.txt index c9d00cecc..a5f001b2f 100644 --- a/samples/autoVariables/out.txt +++ b/samples/autoVariables/out.txt @@ -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. diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index eb4d67fcb..ec7c82047 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -133,7 +133,7 @@ private: " int num = 2;\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" "{\n" @@ -159,7 +159,7 @@ private: " int num = 2;\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" " void func1(int **res);\n" @@ -188,7 +188,7 @@ private: " int x[100];\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 @@ -206,7 +206,7 @@ private: " char 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 @@ -222,7 +222,7 @@ private: " char a[10];\n" " x->str = a;\n" "}", 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 @@ -240,7 +240,7 @@ private: " int i = 0;\n" " p = &i;\n" "}", 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" " s = foo;\n" @@ -258,7 +258,7 @@ private: " p = &p_fp->i;\n" " p = &fp.f->i;\n" "}", 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 @@ -371,7 +371,7 @@ private: " struct A a = bar();\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" " struct S *p = glob;\n" @@ -390,7 +390,7 @@ private: " s8 p[10];\n" // <- p is array => error " *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 @@ -450,7 +450,7 @@ private: " int num=2;" " 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() { @@ -462,7 +462,7 @@ private: " int num=2;" " 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() { @@ -471,7 +471,7 @@ private: " XPoint 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 @@ -479,7 +479,7 @@ private: " 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() {