Fix 10361: false negative: uninitvar (std::next(iterator)) (#4256)

This commit is contained in:
Paul Fultz II 2022-07-09 00:39:04 -05:00 committed by GitHub
parent b246781da6
commit edebe746bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 11 deletions

View File

@ -7305,8 +7305,14 @@ static bool needsInitialization(const Variable* var, bool cpp)
return true;
if (var->type() && var->type()->needInitialization == Type::NeedInitialization::True)
return true;
if (var->valueType() && (var->valueType()->isPrimitive() || var->valueType()->type == ValueType::Type::POD))
return true;
if (var->valueType()) {
if (var->valueType()->isPrimitive())
return true;
if (var->valueType()->type == ValueType::Type::POD)
return true;
if (var->valueType()->type == ValueType::Type::ITERATOR)
return true;
}
return false;
}

View File

@ -413,19 +413,19 @@ void uninitvar_std_next(const std::vector<int> &v, int count)
if (std::next(v.begin(), count) != v.end()) {}
std::vector<int>::iterator it;
// TODO-cppcheck-suppress uninitvar
// cppcheck-suppress uninitvar
if (std::next(it) != v.end()) {}
std::vector<int>::const_iterator const_it;
// TODO-cppcheck-suppress uninitvar
// cppcheck-suppress uninitvar
if (std::next(const_it) != v.end()) {}
std::vector<int>::reverse_iterator rit;
// TODO-cppcheck-suppress uninitvar
// cppcheck-suppress uninitvar
if (std::next(rit) != v.rend()) {}
std::vector<int>::const_reverse_iterator const_rit;
// TODO-cppcheck-suppress uninitvar
// cppcheck-suppress uninitvar
if (std::next(const_rit) != v.rend()) {}
}
@ -436,19 +436,19 @@ void uninitvar_std_prev(const std::vector<int> &v, int count)
if (std::prev(v.begin(), count) != v.end()) {}
std::vector<int>::iterator it;
// TODO-cppcheck-suppress uninitvar
// cppcheck-suppress uninitvar
if (std::prev(it) != v.end()) {}
std::vector<int>::const_iterator const_it;
// TODO-cppcheck-suppress uninitvar
// cppcheck-suppress uninitvar
if (std::prev(const_it) != v.end()) {}
std::vector<int>::reverse_iterator rit;
// TODO-cppcheck-suppress uninitvar
// cppcheck-suppress uninitvar
if (std::prev(rit) != v.rend()) {}
std::vector<int>::const_reverse_iterator const_rit;
// TODO-cppcheck-suppress uninitvar
// cppcheck-suppress uninitvar
if (std::prev(const_rit) != v.rend()) {}
}
@ -4095,7 +4095,7 @@ void stdalgorithm(const std::list<int> &ints1, const std::list<int> &ints2)
// #9455
std::list<int>::const_iterator uninitItBegin;
std::list<int>::const_iterator uninitItEnd;
// @todo cppcheck-suppress uninitvar
// cppcheck-suppress uninitvar
if (std::find(uninitItBegin, uninitItEnd, 123) == uninitItEnd) {}
// <!-- InputIterator std::find_if(InputIterator first, InputIterator last, UnaryPredicate val) -->