diff options
Diffstat (limited to 'src/analysis')
-rw-r--r-- | src/analysis/analysis.cpp | 98 | ||||
-rw-r--r-- | src/analysis/analysis.h | 14 | ||||
-rw-r--r-- | src/analysis/expression.cpp | 1 | ||||
-rw-r--r-- | src/analysis/ref.cpp | 1 | ||||
-rw-r--r-- | src/analysis/reports.cpp | 133 | ||||
-rw-r--r-- | src/analysis/reports.h | 51 | ||||
-rw-r--r-- | src/analysis/statement.cpp | 1 |
7 files changed, 187 insertions, 112 deletions
diff --git a/src/analysis/analysis.cpp b/src/analysis/analysis.cpp index 0a85a2d..5c73bc3 100644 --- a/src/analysis/analysis.cpp +++ b/src/analysis/analysis.cpp @@ -252,104 +252,6 @@ int findBackLocation(Node *node) return loc; } -// check is var from node can be checked for null pointer -bool checkForReport(Node *node, - const WalkItem &wi) -{ - node = skipNop(node); - return node && - (node == PARM_DECL || node == VAR_DECL) && - isIn(node->label, wi.needCheckNullVars); -} - -// report about useless check for null pointer -void reportUselessCheck(Node *node, - const std::string &var) -{ - Log::warn(findBackLocation(node), - "Useless variable check '%s'. It already was checked before", - var); -} - -// report about null pointer if need for node -void reportParmDeclNullPointer(Node *mainNode, - Node *node, - const WalkItem &wi) -{ - node = skipNop(node); - if (node) - { - if (!node->label.empty()) - { - if (node == PARM_DECL) - { - if (isIn(node->label, wi.needCheckNullVars)) - { - Log::warn(findBackLocation(mainNode), - "Using parameter '%s' without checking for null pointer", - node->label); - } - } - else if (node == VAR_DECL) - { - if (isIn(node->label, wi.needCheckNullVars)) - { - Log::warn(findBackLocation(mainNode), - "Using variable '%s' without checking for null pointer", - node->label); - } - } - } - else if (node == COMPONENT_REF) - { - std::string var = getComponentRefVariable(node); - if (isIn(var, wi.needCheckNullVars)) - { - Log::warn(findBackLocation(mainNode), - "Using field '%s' without checking for null pointer", - var); - } - } - } -} - -void reportPossibleNullPointer(Node *node, - const std::string &label) -{ - Log::warn(findBackLocation(node), - "warning: possible null argument '%s' where non-null required", - label); -} - -void reportParmDeclAttrNullPointer(Node *mainNode, - Node *node, - const WalkItem &wi) -{ - node = skipNop(node); - if (node) - { - if (!node->label.empty()) - { - if (node == PARM_DECL) - { - if (isIn(node->label, wi.needCheckNullVars)) - reportPossibleNullPointer(mainNode, node->label); - } - else if (node == VAR_DECL) - { - if (isIn(node->label, wi.needCheckNullVars)) - reportPossibleNullPointer(mainNode, node->label); - } - } - else if (node == COMPONENT_REF) - { - std::string var = getComponentRefVariable(node); - if (isIn(var, wi.needCheckNullVars)) - reportPossibleNullPointer(mainNode, node->label); - } - } -} - // skip all child nodes and return non nop child Node *skipNop(Node *node) { diff --git a/src/analysis/analysis.h b/src/analysis/analysis.h index fdfc6ab..8b38823 100644 --- a/src/analysis/analysis.h +++ b/src/analysis/analysis.h @@ -38,20 +38,6 @@ namespace Analysis int findBackLocation(Node *node); - void reportParmDeclNullPointer(Node *mainNode, - Node *node, - const WalkItem &wi); - - void reportParmDeclAttrNullPointer(Node *mainNode, - Node *node, - const WalkItem &wi); - - void reportUselessCheck(Node *node, - const std::string &var); - - bool checkForReport(Node *node, - const WalkItem &wi); - void addNullVar(WalkItem &wi, const std::string &var); diff --git a/src/analysis/expression.cpp b/src/analysis/expression.cpp index 3069d48..cd1cbe2 100644 --- a/src/analysis/expression.cpp +++ b/src/analysis/expression.cpp @@ -24,6 +24,7 @@ #include "analysis/analysis.h" #include "analysis/function.h" +#include "analysis/reports.h" #include "analysis/statement.h" #include "analysis/walkitem.h" diff --git a/src/analysis/ref.cpp b/src/analysis/ref.cpp index 2a1aa54..65cb805 100644 --- a/src/analysis/ref.cpp +++ b/src/analysis/ref.cpp @@ -23,6 +23,7 @@ #include "logger.h" #include "analysis/analysis.h" +#include "analysis/reports.h" #include "analysis/walkitem.h" #include "nodes/expr/addr_expr.h" diff --git a/src/analysis/reports.cpp b/src/analysis/reports.cpp new file mode 100644 index 0000000..0fbd73e --- /dev/null +++ b/src/analysis/reports.cpp @@ -0,0 +1,133 @@ +/* + * Copyright (C) 2015 Andrei Karas + * + * This file is part of Paranoid null checker. + * + * 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/reports.h" + +#include "logger.h" + +#include "analysis/analysis.h" +#include "analysis/expression.h" +#include "analysis/walkitem.h" + +#include "nodes/base/node.h" + +#include "localconsts.h" + +namespace Analysis +{ + +// check is var from node can be checked for null pointer +bool checkForReport(Node *node, + const WalkItem &wi) +{ + node = skipNop(node); + return node && + (node == PARM_DECL || node == VAR_DECL) && + isIn(node->label, wi.needCheckNullVars); +} + +// report about useless check for null pointer +void reportUselessCheck(Node *node, + const std::string &var) +{ + Log::warn(findBackLocation(node), + "Useless variable check '%s'. It already was checked before", + var); +} + +// report about null pointer if need for node +void reportParmDeclNullPointer(Node *mainNode, + Node *node, + const WalkItem &wi) +{ + node = skipNop(node); + if (node) + { + if (!node->label.empty()) + { + if (node == PARM_DECL) + { + if (isIn(node->label, wi.needCheckNullVars)) + { + Log::warn(findBackLocation(mainNode), + "Using parameter '%s' without checking for null pointer", + node->label); + } + } + else if (node == VAR_DECL) + { + if (isIn(node->label, wi.needCheckNullVars)) + { + Log::warn(findBackLocation(mainNode), + "Using variable '%s' without checking for null pointer", + node->label); + } + } + } + else if (node == COMPONENT_REF) + { + std::string var = getComponentRefVariable(node); + if (isIn(var, wi.needCheckNullVars)) + { + Log::warn(findBackLocation(mainNode), + "Using field '%s' without checking for null pointer", + var); + } + } + } +} + +void reportPossibleNullPointer(Node *node, + const std::string &label) +{ + Log::warn(findBackLocation(node), + "warning: possible null argument '%s' where non-null required", + label); +} + +void reportParmDeclAttrNullPointer(Node *mainNode, + Node *node, + const WalkItem &wi) +{ + node = skipNop(node); + if (node) + { + if (!node->label.empty()) + { + if (node == PARM_DECL) + { + if (isIn(node->label, wi.needCheckNullVars)) + reportPossibleNullPointer(mainNode, node->label); + } + else if (node == VAR_DECL) + { + if (isIn(node->label, wi.needCheckNullVars)) + reportPossibleNullPointer(mainNode, node->label); + } + } + else if (node == COMPONENT_REF) + { + std::string var = getComponentRefVariable(node); + if (isIn(var, wi.needCheckNullVars)) + reportPossibleNullPointer(mainNode, node->label); + } + } +} + +} diff --git a/src/analysis/reports.h b/src/analysis/reports.h new file mode 100644 index 0000000..d6e21dc --- /dev/null +++ b/src/analysis/reports.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2015 Andrei Karas + * + * This file is part of Paranoid null checker. + * + * 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_REPORTS_H +#define ANALYSIS_REPORTS_H + +#include "includes.h" + +#include <set> +#include <string> + +struct Node; +struct WalkItem; + +namespace Analysis +{ + void reportParmDeclNullPointer(Node *mainNode, + Node *node, + const WalkItem &wi); + + void reportParmDeclAttrNullPointer(Node *mainNode, + Node *node, + const WalkItem &wi); + + void reportPossibleNullPointer(Node *node, + const std::string &label); + + void reportUselessCheck(Node *node, + const std::string &var); + + bool checkForReport(Node *node, + const WalkItem &wi); +} + +#endif // ANALYSIS_REPORTS_H diff --git a/src/analysis/statement.cpp b/src/analysis/statement.cpp index 263d622..5791819 100644 --- a/src/analysis/statement.cpp +++ b/src/analysis/statement.cpp @@ -23,6 +23,7 @@ #include "logger.h" #include "analysis/analysis.h" +#include "analysis/reports.h" #include "analysis/walkitem.h" #include "nodes/expr/eq_expr.h" |