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