summaryrefslogtreecommitdiff
path: root/src/analysis
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-06-10 01:37:58 +0300
committerAndrei Karas <akaras@inbox.ru>2015-06-10 02:00:29 +0300
commit60331c2bd81402074979ecd3fa5c433240521d2b (patch)
treedb4349f5ab4891e55fc655de58599f2280634d5b /src/analysis
parent33bd8b0eab143c6ab7cf228f8ad429daa3cba060 (diff)
downloadparanucker-60331c2bd81402074979ecd3fa5c433240521d2b.tar.gz
paranucker-60331c2bd81402074979ecd3fa5c433240521d2b.tar.bz2
paranucker-60331c2bd81402074979ecd3fa5c433240521d2b.tar.xz
paranucker-60331c2bd81402074979ecd3fa5c433240521d2b.zip
Analyse VAR_DECL for using possible null pointer input variable.
Diffstat (limited to 'src/analysis')
-rw-r--r--src/analysis/analysis.cpp5
-rw-r--r--src/analysis/declaration.cpp56
-rw-r--r--src/analysis/declaration.h33
3 files changed, 94 insertions, 0 deletions
diff --git a/src/analysis/analysis.cpp b/src/analysis/analysis.cpp
index d58e296..494852c 100644
--- a/src/analysis/analysis.cpp
+++ b/src/analysis/analysis.cpp
@@ -20,12 +20,15 @@
#include "analysis/analysis.h"
#include "command.h"
+#include "logger.h"
+#include "analysis/declaration.h"
#include "analysis/expression.h"
#include "analysis/function.h"
#include "analysis/walkitem.h"
#include "nodes/decl/function_decl.h"
+#include "nodes/decl/var_decl.h"
#include "nodes/expr/modify_expr.h"
#include "nodes/expr/pointerplus_expr.h"
@@ -74,6 +77,8 @@ WalkItem analyseNode(Node *node, WalkItem wi)
return analyseModifyExpr(static_cast<ModifyExprNode*>(node), wi);
case POINTER_PLUS_EXPR:
return analysePointerPlusExpr(static_cast<PointerPlusExprNode*>(node), wi);
+ case VAR_DECL:
+ return analyseVarDecl(static_cast<VarDeclNode*>(node), wi);
default:
break;
}
diff --git a/src/analysis/declaration.cpp b/src/analysis/declaration.cpp
new file mode 100644
index 0000000..04cb7b1
--- /dev/null
+++ b/src/analysis/declaration.cpp
@@ -0,0 +1,56 @@
+/*
+ * 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/declaration.h"
+
+#include "command.h"
+#include "logger.h"
+
+#include "analysis/analysis.h"
+#include "analysis/walkitem.h"
+
+#include "nodes/decl/var_decl.h"
+
+#include <set>
+
+#include "localconsts.h"
+
+namespace Analysis
+{
+
+WalkItem analyseVarDecl(VarDeclNode *node, WalkItem wi)
+{
+ // need atleast one arg for check
+ if (!node->initial || command == FindArgs)
+ return wi;
+
+ Node *initial = node->initial;
+ if (initial->nodeType == PARM_DECL)
+ {
+ if (wi.checkNullVars.find(initial->label) != wi.checkNullVars.end())
+ {
+ Log::warn(findBackLocation(node),
+ "Using variable without check for NULL");
+ }
+ }
+
+ return wi;
+}
+
+}
diff --git a/src/analysis/declaration.h b/src/analysis/declaration.h
new file mode 100644
index 0000000..88dbb3f
--- /dev/null
+++ b/src/analysis/declaration.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_DECLARATION_H
+#define ANALYSIS_DECLARATION_H
+
+#include "includes.h"
+
+struct VarDeclNode;
+struct WalkItem;
+
+namespace Analysis
+{
+ WalkItem analyseVarDecl(VarDeclNode *node, WalkItem wi);
+}
+
+#endif // ANALYSIS_DECLARATION_H