Opened 4 months ago
Closed 9 days ago
#14725 closed defect (fixed)
False positive: redundantIfRemove when conditional code has extra code
| Reported by: | Daniel Marjamäki | Owned by: | noone |
|---|---|---|---|
| Priority: | Normal | Milestone: | 2.22 |
| Component: | False positive | Version: | 1.65 |
| Keywords: | redundantIfRemove simple | Cc: |
Description (last modified by )
Example code:
#include <set> #include <string> void unsubscribe(const std::string& key); std::set<std::string> g_params; void del(const std::string& key) { if (g_params.find(key) != g_params.end()) { g_params.erase(key); unsubscribe(key); // only call if key was present } }
Command:
cppcheck --enable=style fp.cpp
False positive:
fp.cpp:9:9: style: Redundant checking of STL container element existence before removing it. [redundantIfRemove]
if (g_params.find(key) != g_params.end()) {
^
Without a check, the unsubscribe function would always be called.
Change History (3)
comment:2 by , 4 months ago
| Description: | modified (diff) |
|---|---|
| Version: | → 1.65 |
This started with 1.65 and has been bisected to https://github.com/cppcheck-opensource/cppcheck/commit/776ad32a0b832758eb1520289a791b206d28bdf9.
comment:3 by , 9 days ago
| Milestone: | → 2.22 |
|---|---|
| Resolution: | → fixed |
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Also, the only test case we have is based on a non-existent
string::remove()method.E.g.
QSethasremove(), but currently there is no validation of the container.