diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-07-10 02:04:22 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-07-10 02:22:33 +0300 |
commit | 4e5bece0cc29f7068c5c46c173d385f3e6e75482 (patch) | |
tree | e74707a7372f99e471fc84e3a5936778168ae4d7 /src | |
parent | 9a99b7ca6d59b3f9d19c05b5512b5cc3efd6a5a0 (diff) | |
download | paranucker-4e5bece0cc29f7068c5c46c173d385f3e6e75482.tar.gz paranucker-4e5bece0cc29f7068c5c46c173d385f3e6e75482.tar.bz2 paranucker-4e5bece0cc29f7068c5c46c173d385f3e6e75482.tar.xz paranucker-4e5bece0cc29f7068c5c46c173d385f3e6e75482.zip |
Disable check for useless checks in second check in while condition.
This fix false positive in this example:
while(ptr)
{
...
}
Diffstat (limited to 'src')
-rw-r--r-- | src/analysis/reports.cpp | 3 | ||||
-rw-r--r-- | src/analysis/statement.cpp | 9 | ||||
-rw-r--r-- | src/command.h | 5 | ||||
-rw-r--r-- | src/plugin.cpp | 12 |
4 files changed, 22 insertions, 7 deletions
diff --git a/src/analysis/reports.cpp b/src/analysis/reports.cpp index 5a46dfe..af5806b 100644 --- a/src/analysis/reports.cpp +++ b/src/analysis/reports.cpp @@ -19,6 +19,7 @@ #include "analysis/reports.h" +#include "command.h" #include "logger.h" #include "analysis/analysis.h" @@ -46,6 +47,8 @@ bool checkForReport(Node *node, void reportUselessCheck(Node *node, const std::string &var) { + if (!checkCommand(DetectUseless)) + return; Log::warn(findBackLocation(node), "Useless variable check '%s'. It already was checked before", var); diff --git a/src/analysis/statement.cpp b/src/analysis/statement.cpp index a9bfef4..f8b428f 100644 --- a/src/analysis/statement.cpp +++ b/src/analysis/statement.cpp @@ -196,8 +196,6 @@ void analyseWhileStmt(WhileStmtNode *node, const WalkItem &wi, WalkItem &wo) WalkItem wi2 = wi; if (wco.cleanExpr) removeNeedCheckNullVarsSetAll(wi2, wco.checkedThenNonNullVars); -// wi2.needCheckNullVars.insert(wco.checkedThenNullVars.begin(), -// wco.checkedThenNullVars.end()); addKnownNullVarsWithLinked(wi2, wco, wco.checkedThenNullVars); addKnownNonNullVarsWithLinked(wi2, wco, wco.checkedThenNonNullVars); wi2.needCheckNullVars = wi2.knownVars; @@ -233,9 +231,12 @@ void analyseWhileStmt(WhileStmtNode *node, const WalkItem &wi, WalkItem &wo) { addNeedCheckNullVars2(wo2, wo); - wci = wo; - wco = wo; + const Command oldCommand = command; + disableCommand(DetectUseless); + wci = wo2; + wco = wo2; walkTree(condNode, wci, wco); + command = oldCommand; Log::dumpWI(node, "wco2 ", wco); } diff --git a/src/command.h b/src/command.h index a1ef995..7fb7386 100644 --- a/src/command.h +++ b/src/command.h @@ -21,6 +21,8 @@ #define COMMAND_H #define checkCommand(val) ((command & Command::val) == Command::val) +#define disableCommand(val) command = static_cast<Command>(static_cast<int>( \ + command | Command::val) ^ static_cast<int>(Command::val)) enum Command : int { @@ -31,7 +33,8 @@ enum Command : int MemoryUsage = 8, FindArgs = 16, DetectNullPointers = 32, - DumpNullPointers = 64 + DumpNullPointers = 64, + DetectUseless = 128 }; extern Command command; diff --git a/src/plugin.cpp b/src/plugin.cpp index c1d9b18..cf611f5 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -40,6 +40,12 @@ Command command = Command::DetectNullPointers; std::map<tree, Node*> foundNodesMap; std::map<Node*, Node*> updateNodesMap; +Command operator |(const Command &cmd1, const Command &cmd2) +{ + return static_cast<Command>(static_cast<int>(cmd1) + | static_cast<int>(cmd2)); +} + static void pre_generic(void *gcc_data, void *user_data A_UNUSED) { @@ -94,11 +100,13 @@ int plugin_init (struct plugin_name_args *plugin_info, } else if (cmd == "detectnullpointers") { - command = Command::DetectNullPointers; + command = Command::DetectNullPointers | + Command::DetectUseless; } else if (cmd == "dumpnullpointers") { - command = Command::DumpNullPointers; + command = Command::DumpNullPointers | + Command::DetectUseless; } else { |