Skip to content

Commit 9248524

Browse files
committed
Restore severity for 'autoVariables'
1 parent 0cb45b1 commit 9248524

3 files changed

Lines changed: 16 additions & 16 deletions

File tree

lib/checkautovariables.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,14 @@ void CheckAutoVariables::errorReturnPointerToLocalArray(const Token *tok)
339339
void CheckAutoVariables::errorAutoVariableAssignment(const Token *tok, bool inconclusive)
340340
{
341341
if (!inconclusive) {
342-
reportError(tok, Severity::warning, "autoVariables",
342+
reportError(tok, Severity::error, "autoVariables",
343343
"Address of local auto-variable assigned to a function parameter.\n"
344344
"Dangerous assignment - the function parameter is assigned the address of a local "
345345
"auto-variable. Local auto-variables are reserved from the stack which "
346346
"is freed when the function ends. So the pointer to a local variable "
347347
"is invalid after the function ends.", CWE562, false);
348348
} else {
349-
reportError(tok, Severity::warning, "autoVariables",
349+
reportError(tok, Severity::error, "autoVariables",
350350
"Address of local auto-variable assigned to a function parameter.\n"
351351
"Function parameter is assigned the address of a local auto-variable. "
352352
"Local auto-variables are reserved from the stack which is freed when "

samples/autoVariables/out.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[samples\autoVariables\bad.c:4]: (warning) Address of local auto-variable assigned to a function parameter.
1+
[samples\autoVariables\bad.c:4]: (error) Address of local auto-variable assigned to a function parameter.

test/testautovariables.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class TestAutoVariables : public TestFixture {
133133
" int num = 2;\n"
134134
" *res = #\n"
135135
"}");
136-
ASSERT_EQUALS("[test.cpp:4]: (warning) Address of local auto-variable assigned to a function parameter.\n", errout.str());
136+
ASSERT_EQUALS("[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
137137

138138
check("void func1(int **res)\n"
139139
"{\n"
@@ -159,7 +159,7 @@ class TestAutoVariables : public TestFixture {
159159
" int num = 2;\n"
160160
" *res = #\n"
161161
"}");
162-
ASSERT_EQUALS("[test.cpp:7]: (warning) Address of local auto-variable assigned to a function parameter.\n", errout.str());
162+
ASSERT_EQUALS("[test.cpp:7]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
163163

164164
check("class Fred {\n"
165165
" void func1(int **res);\n"
@@ -188,7 +188,7 @@ class TestAutoVariables : public TestFixture {
188188
" int x[100];\n"
189189
" *p = x;\n"
190190
"}");
191-
ASSERT_EQUALS("[test.cpp:4]: (warning) Address of local auto-variable assigned to a function parameter.\n", errout.str());
191+
ASSERT_EQUALS("[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
192192
}
193193

194194
void testautovar4() { // ticket #2928
@@ -206,7 +206,7 @@ class TestAutoVariables : public TestFixture {
206206
" char a;\n"
207207
" ab->a = &a;\n"
208208
"}");
209-
ASSERT_EQUALS("[test.cpp:4]: (warning) Address of local auto-variable assigned to a function parameter.\n", errout.str());
209+
ASSERT_EQUALS("[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
210210
}
211211

212212
void testautovar6() { // ticket #2931
@@ -222,7 +222,7 @@ class TestAutoVariables : public TestFixture {
222222
" char a[10];\n"
223223
" x->str = a;\n"
224224
"}", true);
225-
ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout.str());
225+
ASSERT_EQUALS("[test.cpp:4]: (error, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout.str());
226226
}
227227

228228
void testautovar7() { // ticket #3066
@@ -240,7 +240,7 @@ class TestAutoVariables : public TestFixture {
240240
" int i = 0;\n"
241241
" p = &i;\n"
242242
"}", false);
243-
ASSERT_EQUALS("[test.cpp:3]: (warning) Address of local auto-variable assigned to a function parameter.\n", errout.str());
243+
ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
244244

245245
check("void foo(std::string& s) {\n"
246246
" s = foo;\n"
@@ -258,7 +258,7 @@ class TestAutoVariables : public TestFixture {
258258
" p = &p_fp->i;\n"
259259
" p = &fp.f->i;\n"
260260
"}", false);
261-
ASSERT_EQUALS("[test.cpp:6]: (warning) Address of local auto-variable assigned to a function parameter.\n", errout.str());
261+
ASSERT_EQUALS("[test.cpp:6]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
262262
}
263263

264264
void testautovar10() { // #2930 - assignment of function parameter
@@ -371,7 +371,7 @@ class TestAutoVariables : public TestFixture {
371371
" struct A a = bar();\n"
372372
" *p = &a.data[0];\n"
373373
"}");
374-
ASSERT_EQUALS("[test.cpp:6]: (warning) Address of local auto-variable assigned to a function parameter.\n", errout.str());
374+
ASSERT_EQUALS("[test.cpp:6]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
375375

376376
check("void f(char **out) {\n"
377377
" struct S *p = glob;\n"
@@ -390,7 +390,7 @@ class TestAutoVariables : public TestFixture {
390390
" s8 p[10];\n" // <- p is array => error
391391
" *out = &p[1];\n"
392392
"}");
393-
ASSERT_EQUALS("[test.cpp:3]: (warning) Address of local auto-variable assigned to a function parameter.\n", errout.str());
393+
ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
394394
}
395395

396396
void testautovar12() { // Ticket #5024, #5050 - Crash on invalid input
@@ -450,7 +450,7 @@ class TestAutoVariables : public TestFixture {
450450
" int num=2;"
451451
" arr[0]=&num;\n"
452452
"}");
453-
ASSERT_EQUALS("[test.cpp:3]: (warning) Address of local auto-variable assigned to a function parameter.\n", errout.str());
453+
ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
454454
}
455455

456456
void testautovar_array2() {
@@ -462,7 +462,7 @@ class TestAutoVariables : public TestFixture {
462462
" int num=2;"
463463
" arr[0]=&num;\n"
464464
"}");
465-
ASSERT_EQUALS("[test.cpp:6]: (warning) Address of local auto-variable assigned to a function parameter.\n", errout.str());
465+
ASSERT_EQUALS("[test.cpp:6]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
466466
}
467467

468468
void testautovar_normal() {
@@ -471,15 +471,15 @@ class TestAutoVariables : public TestFixture {
471471
" XPoint DropPoint;\n"
472472
" ds->location_data = (XtPointer *)&DropPoint;\n"
473473
"}");
474-
ASSERT_EQUALS("[test.cpp:4]: (warning) Address of local auto-variable assigned to a function parameter.\n", errout.str());
474+
ASSERT_EQUALS("[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
475475
}
476476

477477
void testautovar_ptrptr() { // #6596
478478
check("void remove_duplicate_matches (char **matches) {\n"
479479
" char dead_slot;\n"
480480
" matches[0] = (char *)&dead_slot;\n"
481481
"}");
482-
ASSERT_EQUALS("[test.cpp:3]: (warning) Address of local auto-variable assigned to a function parameter.\n", errout.str());
482+
ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
483483
}
484484

485485
void testautovar_return1() {

0 commit comments

Comments
 (0)