diff --git a/lib/checkother.cpp b/lib/checkother.cpp index a4d079784..939b4e5a3 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -550,9 +550,9 @@ void CheckOther::redundantAssignmentError(const Token *tok1, const Token* tok2, void CheckOther::redundantInitializationError(const Token *tok1, const Token* tok2, const std::string& var, bool inconclusive) { - const std::list callstack = { tok1, tok2 }; + const std::list callstack = { tok2, tok1 }; reportError(callstack, Severity::style, "redundantInitialization", - "$symbol:" + var + "\nRedundant initialization for '$symbol'. The initialized value is never used.", + "$symbol:" + var + "\nRedundant initialization for '$symbol'. The initialized value is overwritten before it is read.", CWE563, inconclusive); } diff --git a/test/cfg/posix.c b/test/cfg/posix.c index 719e715b0..7f0a6df1a 100644 --- a/test/cfg/posix.c +++ b/test/cfg/posix.c @@ -400,9 +400,9 @@ void timet_h(struct timespec* ptp1) void dl(const char* libname, const char* func) { + // cppcheck-suppress redundantInitialization void* lib = dlopen(libname, RTLD_NOW); // cppcheck-suppress resourceLeak - // cppcheck-suppress redundantAssignment lib = dlopen(libname, RTLD_LAZY); const char* funcname; // cppcheck-suppress uninitvar diff --git a/test/testother.cpp b/test/testother.cpp index a7e09b6a2..0c2ec457e 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -6554,13 +6554,13 @@ private: " int err = -ENOMEM;\n" " err = dostuff();\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Redundant initialization for 'err'. The initialized value is never used.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (style) Redundant initialization for 'err'. The initialized value is overwritten before it is read.\n", errout.str()); check("void f() {\n" " struct S s = {1,2,3};\n" " s = dostuff();\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Redundant initialization for 's'. The initialized value is never used.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (style) Redundant initialization for 's'. The initialized value is overwritten before it is read.\n", errout.str()); check("void f() {\n" " int *p = NULL;\n"