72a884
From 13eeebd2fb3005abc876957c68bde6a92510aa44 Mon Sep 17 00:00:00 2001
72a884
From: Mark Dufour <m.dufour@kopano.com>
72a884
Date: Tue, 14 Feb 2017 10:53:14 +0100
72a884
Subject: [PATCH] [Coverity] fix issue reported for wrapper argument checking
72a884
72a884
Fix Coverity issue reported for wrapper argument checking:
72a884
72a884
"Null-checking args suggests that it may be null, but it has already
72a884
been dereferenced on all paths leading to the check."
72a884
72a884
So 'args' is null checked, but after dereferencing it with
72a884
PyTuple_Check(args).
72a884
---
72a884
 Source/Modules/python.cxx | 11 ++++++++---
72a884
 1 file changed, 8 insertions(+), 3 deletions(-)
72a884
72a884
diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx
72a884
index a6801fc4e..5e058e773 100644
72a884
--- a/Source/Modules/python.cxx
72a884
+++ b/Source/Modules/python.cxx
72a884
@@ -2541,9 +2541,14 @@ public:
72a884
 
72a884
     if (!fastunpack) {
72a884
       Wrapper_add_local(f, "ii", "Py_ssize_t ii");
72a884
-      if (maxargs - (add_self ? 1 : 0) > 0)
72a884
-	Append(f->code, "if (!PyTuple_Check(args)) SWIG_fail;\n");
72a884
-      Append(f->code, "argc = args ? PyObject_Length(args) : 0;\n");
72a884
+
72a884
+      if (maxargs - (add_self ? 1 : 0) > 0) {
72a884
+        Append(f->code, "if (!PyTuple_Check(args)) SWIG_fail;\n");
72a884
+        Append(f->code, "argc = PyObject_Length(args);\n");
72a884
+      } else {
72a884
+        Append(f->code, "argc = args ? PyObject_Length(args) : 0;\n");
72a884
+      }
72a884
+
72a884
       if (add_self)
72a884
 	Append(f->code, "argv[0] = self;\n");
72a884
       Printf(f->code, "for (ii = 0; (ii < %d) && (ii < argc); ii++) {\n", add_self ? maxargs - 1 : maxargs);
72a884
-- 
72a884
2.14.3
72a884