Blob Blame History Raw
From 13eeebd2fb3005abc876957c68bde6a92510aa44 Mon Sep 17 00:00:00 2001
From: Mark Dufour <m.dufour@kopano.com>
Date: Tue, 14 Feb 2017 10:53:14 +0100
Subject: [PATCH] [Coverity] fix issue reported for wrapper argument checking

Fix Coverity issue reported for wrapper argument checking:

"Null-checking args suggests that it may be null, but it has already
been dereferenced on all paths leading to the check."

So 'args' is null checked, but after dereferencing it with
PyTuple_Check(args).
---
 Source/Modules/python.cxx | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx
index a6801fc4e..5e058e773 100644
--- a/Source/Modules/python.cxx
+++ b/Source/Modules/python.cxx
@@ -2541,9 +2541,14 @@ public:
 
     if (!fastunpack) {
       Wrapper_add_local(f, "ii", "Py_ssize_t ii");
-      if (maxargs - (add_self ? 1 : 0) > 0)
-	Append(f->code, "if (!PyTuple_Check(args)) SWIG_fail;\n");
-      Append(f->code, "argc = args ? PyObject_Length(args) : 0;\n");
+
+      if (maxargs - (add_self ? 1 : 0) > 0) {
+        Append(f->code, "if (!PyTuple_Check(args)) SWIG_fail;\n");
+        Append(f->code, "argc = PyObject_Length(args);\n");
+      } else {
+        Append(f->code, "argc = args ? PyObject_Length(args) : 0;\n");
+      }
+
       if (add_self)
 	Append(f->code, "argv[0] = self;\n");
       Printf(f->code, "for (ii = 0; (ii < %d) && (ii < argc); ii++) {\n", add_self ? maxargs - 1 : maxargs);
-- 
2.14.3