Fixed #4203 (Don't warn about setting NULL value for pointers and not using that value)
This commit is contained in:
parent
9b093b404c
commit
a64669b1ec
|
@ -5,4 +5,4 @@ compiler:
|
|||
script:
|
||||
- make test
|
||||
- $CXX -o cppcheck -O2 cli/*.cpp lib/*.cpp -Ilib
|
||||
- ./cppcheck --error-exitcode=1 -Ilib --enable=style --suppress=unreadVariable --suppress=duplicateBranch --suppress=stlIfStrFind -q cli gui lib -igui/test
|
||||
- ./cppcheck --error-exitcode=1 -Ilib --enable=style --suppress=duplicateBranch --suppress=stlIfStrFind -q cli gui lib -igui/test
|
||||
|
|
|
@ -250,7 +250,7 @@ void Variables::write(unsigned int varid, const Token* tok)
|
|||
|
||||
if (usage) {
|
||||
usage->_write = true;
|
||||
if (!usage->_var->isStatic())
|
||||
if (!usage->_var->isStatic() && !Token::simpleMatch(tok->next(), "= 0 ;"))
|
||||
usage->_read = false;
|
||||
usage->_lastAccess = tok;
|
||||
}
|
||||
|
|
|
@ -144,6 +144,7 @@ private:
|
|||
TEST_CASE(localvarIfNOT); // #3104 - if ( NOT var )
|
||||
TEST_CASE(localvarAnd); // #3672
|
||||
TEST_CASE(localvarSwitch); // #3744 - false positive when localvar is used in switch
|
||||
TEST_CASE(localvarNULL); // #4203 - Setting NULL value is not redundant - it is safe
|
||||
|
||||
TEST_CASE(crash1);
|
||||
}
|
||||
|
@ -3317,6 +3318,16 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void localvarNULL() { // #4203 - Setting NULL value is not redundant - it is safe
|
||||
functionVariableUsage("void f() {\n"
|
||||
" char *p = malloc(100);\n"
|
||||
" foo(p);\n"
|
||||
" free(p);\n"
|
||||
" p = NULL;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void crash1() {
|
||||
functionVariableUsage("SAL_WNODEPRECATED_DECLARATIONS_PUSH\n"
|
||||
"void convertToTokenArray() {\n"
|
||||
|
|
Loading…
Reference in New Issue