summaryrefslogtreecommitdiff
path: root/src/analysis/statement.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-06-11 23:42:07 +0300
committerAndrei Karas <akaras@inbox.ru>2015-06-11 23:42:07 +0300
commite8e75ca7639bf3a8e34391aaa33f90c18905e977 (patch)
tree5201e8207d73f89a8dede013ba5780d10a1b480b /src/analysis/statement.cpp
parent23f9052202cac18045c1a49465ac765fbd155f56 (diff)
downloadparanucker-e8e75ca7639bf3a8e34391aaa33f90c18905e977.tar.gz
paranucker-e8e75ca7639bf3a8e34391aaa33f90c18905e977.tar.bz2
paranucker-e8e75ca7639bf3a8e34391aaa33f90c18905e977.tar.xz
paranucker-e8e75ca7639bf3a8e34391aaa33f90c18905e977.zip
Fix some issues in test6.
Now if variable check happend before other code variable will not trigger warning. Example: if (!a) return; *a = 10;
Diffstat (limited to 'src/analysis/statement.cpp')
-rw-r--r--src/analysis/statement.cpp26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/analysis/statement.cpp b/src/analysis/statement.cpp
index a585adb..4d948d3 100644
--- a/src/analysis/statement.cpp
+++ b/src/analysis/statement.cpp
@@ -57,7 +57,7 @@ void analyseIfStmt(IfStmtNode *node, const WalkItem &wi, WalkItem &wo)
Node *node1 = eq->args[0];
// INTEGER_CST?
Node *node2 = eq->args[1];
- // if (var == const)
+ // if (var == 0)
if (node1->nodeType == PARM_DECL &&
node2->nodeType == INTEGER_CST &&
wi.checkNullVars.find(node1->label) != wi.checkNullVars.end() &&
@@ -67,10 +67,13 @@ void analyseIfStmt(IfStmtNode *node, const WalkItem &wi, WalkItem &wo)
// found check for parameter and 0.
// walking to then branch
walkTree(node->thenNode, wi2, wo);
+ wo.removeNullVars.clear();
+
// From else branch remove variable what we just found.
wi2 = wi;
wi2.checkNullVars.erase(node1->label);
walkTree(node->elseNode, wi2, wo);
+ wo.removeNullVars.clear();
wo.stopWalking = true;
//Log::log("add removeNullVars: %s\n", node1->label.c_str());
@@ -79,20 +82,21 @@ void analyseIfStmt(IfStmtNode *node, const WalkItem &wi, WalkItem &wo)
wo.checkNullVars.erase(node1->label);
// need check what return present
+ return;
}
}
else if (node->condition->nodeType == NE_EXPR)
{ // if (... != ..)
- NeExprNode *eq = static_cast<NeExprNode*>(node->condition);
- // need atleast two operands for EQ_EXPR node
- if (eq->args.size() < 2)
+ NeExprNode *ne = static_cast<NeExprNode*>(node->condition);
+ // need atleast two operands for NE_EXPR node
+ if (ne->args.size() < 2)
return;
// PARM_DECL?
- Node *node1 = eq->args[0];
+ Node *node1 = ne->args[0];
// INTEGER_CST?
- Node *node2 = eq->args[1];
- // if (var != const)
+ Node *node2 = ne->args[1];
+ // if (var != 0)
if (node1->nodeType == PARM_DECL &&
node2->nodeType == INTEGER_CST &&
wi.checkNullVars.find(node1->label) != wi.checkNullVars.end() &&
@@ -104,13 +108,21 @@ void analyseIfStmt(IfStmtNode *node, const WalkItem &wi, WalkItem &wo)
wi2.checkNullVars.erase(node1->label);
// From then branch remove variable what we just found.
walkTree(node->thenNode, wi2, wo);
+ wo.removeNullVars.clear();
wi2 = wi;
// walking else node with all variables
walkTree(node->elseNode, wi2, wo);
+ wo.removeNullVars.clear();
wo.stopWalking = true;
return;
}
}
+
+ // default case
+ walkTree(node->thenNode, wi, wo);
+ walkTree(node->elseNode, wi, wo);
+ wo.removeNullVars.clear();
+ wo.stopWalking = true;
}
}