diff options
Diffstat (limited to 'src/analysis')
-rw-r--r-- | src/analysis/analysis.cpp | 5 | ||||
-rw-r--r-- | src/analysis/declaration.cpp | 56 | ||||
-rw-r--r-- | src/analysis/declaration.h | 33 |
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 |