summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/analysis/expression.cpp2
-rw-r--r--src/analysis/function.cpp23
-rw-r--r--src/command.h3
-rw-r--r--src/plugin.cpp9
4 files changed, 24 insertions, 13 deletions
diff --git a/src/analysis/expression.cpp b/src/analysis/expression.cpp
index d18a38f..114208c 100644
--- a/src/analysis/expression.cpp
+++ b/src/analysis/expression.cpp
@@ -38,7 +38,7 @@ namespace Analysis
WalkItem analyseModifyExpr(ModifyExprNode *node, WalkItem wi)
{
// need atleast one arg for check
- if (node->args.empty())
+ if (node->args.empty() || command == FindArgs)
return wi;
Node *arg = node->args[0];
diff --git a/src/analysis/function.cpp b/src/analysis/function.cpp
index 3b9473a..8908987 100644
--- a/src/analysis/function.cpp
+++ b/src/analysis/function.cpp
@@ -107,25 +107,28 @@ WalkItem analyseFunction(FunctionDeclNode *node, WalkItem wi)
// here need check is variables already present in wi2.checkNullVars
if (command == Command::FindArgs)
- {
Log::log("%s: ", node->label.c_str());
- const int sz = node->args.size();
- for (int f = 0; f < sz; f ++)
+
+ const int sz = node->args.size();
+ for (int f = 0; f < sz; f ++)
+ {
+ const TypeNode *const type = types[f];
+ if (type->nodeType != POINTER_TYPE)
+ continue;
+ const ParmDeclNode *const name = node->args[f];
+ if (nonNull.find(f + 1) == nonNull.end())
{
- const TypeNode *const type = types[f];
- if (type->nodeType != POINTER_TYPE)
- continue;
- const ParmDeclNode *const name = node->args[f];
- if (nonNull.find(f + 1) == nonNull.end())
+ if (command == Command::FindArgs)
{
Log::log("%s %s, ",
type->nodeTypeName.c_str(),
name->label.c_str());
- wi2.checkNullVars.insert(name->label);
}
+ wi2.checkNullVars.insert(name->label);
}
- Log::log("\n");
}
+ if (command == Command::FindArgs)
+ Log::log("\n");
if (!wi2.checkNullVars.empty())
{
diff --git a/src/command.h b/src/command.h
index 5441249..17a5586 100644
--- a/src/command.h
+++ b/src/command.h
@@ -27,7 +27,8 @@ enum Command : int
SmallDump,
DumpUnsupported,
MemoryUsage,
- FindArgs
+ FindArgs,
+ DetectNullPointers
};
extern Command command;
diff --git a/src/plugin.cpp b/src/plugin.cpp
index 48765f9..e52c030 100644
--- a/src/plugin.cpp
+++ b/src/plugin.cpp
@@ -40,8 +40,11 @@ static void pre_generic(void *gcc_data,
void *user_data A_UNUSED)
{
Node *node = Generic::parseNodes((tree)gcc_data);
- if (command == Command::FindArgs)
+ if (command == Command::FindArgs ||
+ command == Command::DetectNullPointers)
+ {
Analysis::startWalkTree(node);
+ }
Generic::cleanAllNodes(node);
}
@@ -80,6 +83,10 @@ int plugin_init (struct plugin_name_args *plugin_info,
{
command = Command::FindArgs;
}
+ else if (cmd == "detectnullpointers")
+ {
+ command = Command::DetectNullPointers;
+ }
else
{
error("Plugin %s. Unknown command: %s",