diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-06-17 16:55:12 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-06-17 16:55:12 +0300 |
commit | bde6e9e547a4a17e8ea9901842d1980762b8ed08 (patch) | |
tree | 7f24b238cf3a3ed016c19b7110a36b24358578d5 | |
parent | a23d3c114365ab80ccfc3194db887e258dbec77d (diff) | |
download | paranucker-bde6e9e547a4a17e8ea9901842d1980762b8ed08.tar.gz paranucker-bde6e9e547a4a17e8ea9901842d1980762b8ed08.tar.bz2 paranucker-bde6e9e547a4a17e8ea9901842d1980762b8ed08.tar.xz paranucker-bde6e9e547a4a17e8ea9901842d1980762b8ed08.zip |
Add file for analysis *_REF nodes. Add null pointer analysis in COMPOUND_REF node.
-rw-r--r-- | src/Makefile.files | 2 | ||||
-rw-r--r-- | src/analysis/analysis.cpp | 6 | ||||
-rw-r--r-- | src/analysis/ref.cpp | 67 | ||||
-rw-r--r-- | src/analysis/ref.h | 33 |
4 files changed, 108 insertions, 0 deletions
diff --git a/src/Makefile.files b/src/Makefile.files index 9ffef9d..c95e6e5 100644 --- a/src/Makefile.files +++ b/src/Makefile.files @@ -6,6 +6,8 @@ SRC = analysis/analysis.cpp \ analysis/expression.h \ analysis/function.cpp \ analysis/function.h \ + analysis/ref.cpp \ + analysis/ref.h \ analysis/statement.cpp \ analysis/statement.h \ analysis/walkitem.h \ diff --git a/src/analysis/analysis.cpp b/src/analysis/analysis.cpp index 86fd683..f3a9631 100644 --- a/src/analysis/analysis.cpp +++ b/src/analysis/analysis.cpp @@ -25,6 +25,7 @@ #include "analysis/declaration.h" #include "analysis/expression.h" #include "analysis/function.h" +#include "analysis/ref.h" #include "analysis/statement.h" #include "analysis/walkitem.h" @@ -35,6 +36,8 @@ #include "nodes/expr/modify_expr.h" #include "nodes/expr/pointerplus_expr.h" +#include "nodes/ref/component_ref.h" + #include "nodes/stmt/if_stmt.h" #include "localconsts.h" @@ -146,6 +149,9 @@ void analyseNode(Node *node, const WalkItem &wi, WalkItem &wo) case IF_STMT: analyseIfStmt(static_cast<IfStmtNode*>(node), wi2, wo); break; + case COMPONENT_REF: + analyseComponentRef(static_cast<ComponentRefNode*>(node), wi2, wo); + break; default: break; } diff --git a/src/analysis/ref.cpp b/src/analysis/ref.cpp new file mode 100644 index 0000000..575fd68 --- /dev/null +++ b/src/analysis/ref.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2015 Andrei Karas + * + * This file is part of AstDumper. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "analysis/expression.h" + +#include "command.h" +#include "logger.h" + +#include "analysis/analysis.h" +#include "analysis/walkitem.h" + +#include "nodes/expr/addr_expr.h" +#include "nodes/expr/modify_expr.h" +#include "nodes/expr/pointerplus_expr.h" + +#include "nodes/ref/component_ref.h" +#include "nodes/ref/indirect_ref.h" + +#include <set> + +#include "localconsts.h" + +namespace Analysis +{ + +void analyseComponentRef(ComponentRefNode *node, const WalkItem &wi, WalkItem &wo) +{ + // need atleast one arg for check + if (!node->object || command == FindArgs) + return; + + Node *arg = node->object; + if (arg && arg->nodeType == INDIRECT_REF) + { + IndirectRefNode *refNode = static_cast<IndirectRefNode*>(arg); + // need atleast one arg for check + if (refNode->ref == nullptr) + return; + arg = refNode->ref; + if (arg->nodeType == PARM_DECL) + { + if (wi.checkNullVars.find(arg->label) != wi.checkNullVars.end()) + { + Log::warn(findBackLocation(node), + "Using variable without check for NULL"); + } + } + } +} + +} diff --git a/src/analysis/ref.h b/src/analysis/ref.h new file mode 100644 index 0000000..b562d01 --- /dev/null +++ b/src/analysis/ref.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2015 Andrei Karas + * + * This file is part of AstDumper. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef ANALYSIS_REF_H +#define ANALYSIS_REF_H + +#include "includes.h" + +struct ComponentRefNode; +struct WalkItem; + +namespace Analysis +{ + void analyseComponentRef(ComponentRefNode *node, const WalkItem &wi, WalkItem &wo); +} + +#endif // ANALYSIS_REF_H |