diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-07-01 17:59:18 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-07-01 18:07:45 +0300 |
commit | a9b1e1d3e82cf93af5e4f485b7c05cb932ed092c (patch) | |
tree | 5933aedd5a78ce23fdb10e592ddb999b1d3d165c /src/analysis/reports.cpp | |
parent | 4944b595da0d394e4c33aebdbcbdf1de48c6c0ae (diff) | |
download | paranucker-a9b1e1d3e82cf93af5e4f485b7c05cb932ed092c.tar.gz paranucker-a9b1e1d3e82cf93af5e4f485b7c05cb932ed092c.tar.bz2 paranucker-a9b1e1d3e82cf93af5e4f485b7c05cb932ed092c.tar.xz paranucker-a9b1e1d3e82cf93af5e4f485b7c05cb932ed092c.zip |
Move report functions into separate file.
Diffstat (limited to 'src/analysis/reports.cpp')
-rw-r--r-- | src/analysis/reports.cpp | 133 |
1 files changed, 133 insertions, 0 deletions
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); + } + } +} + +} |