swig/swig-3.0.12-Coverity-fix-issue-reported-for-SWIG_Python_ConvertF.patch

59 lines
1.8 KiB
Diff
Raw Normal View History

From 21f532975f59f0c156c76cc739f5a93f57d8f6cb Mon Sep 17 00:00:00 2001
From: Mark Dufour <m.dufour@kopano.com>
Date: Tue, 14 Feb 2017 10:48:30 +0100
Subject: [PATCH] [Coverity] fix issue reported for
SWIG_Python_ConvertFunctionPtr
Fix Coverity issue reported for SWIG_Python_ConvertFunctionPtr:
"Execution cannot reach this statement: *ptr = vptr;"
Because if 'ty' is null, then desc becomes null and we return with
SWIG_ERROR. So 'ty' cannot be null at 'if (ty)'.
---
Lib/python/pyrun.swg | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg
index ab1237f62..939a69204 100644
--- a/Lib/python/pyrun.swg
+++ b/Lib/python/pyrun.swg
@@ -1287,25 +1287,22 @@ SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) {
return SWIG_ConvertPtr(obj, ptr, ty, 0);
} else {
void *vptr = 0;
-
+ swig_cast_info *tc;
+
/* here we get the method pointer for callbacks */
const char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc);
const char *desc = doc ? strstr(doc, "swig_ptr: ") : 0;
if (desc)
desc = ty ? SWIG_UnpackVoidPtr(desc + 10, &vptr, ty->name) : 0;
- if (!desc)
+ if (!desc)
return SWIG_ERROR;
- if (ty) {
- swig_cast_info *tc = SWIG_TypeCheck(desc,ty);
- if (tc) {
- int newmemory = 0;
- *ptr = SWIG_TypeCast(tc,vptr,&newmemory);
- assert(!newmemory); /* newmemory handling not yet implemented */
- } else {
- return SWIG_ERROR;
- }
+ tc = SWIG_TypeCheck(desc,ty);
+ if (tc) {
+ int newmemory = 0;
+ *ptr = SWIG_TypeCast(tc,vptr,&newmemory);
+ assert(!newmemory); /* newmemory handling not yet implemented */
} else {
- *ptr = vptr;
+ return SWIG_ERROR;
}
return SWIG_OK;
}
--
2.14.3