[PATCH gpgmepy] build: Fix compiler warnings

Paul Schwabauer pschwabauer at intevation.de
Wed Apr 23 17:48:46 CEST 2025


This initializes variables that could be uninitialized and removes the
usage of deprecated functions.
---
 gpgme.i   | 12 ++++++++----
 helpers.c |  3 ++-
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/gpgme.i b/gpgme.i
index f67c45a..0baa551 100644
--- a/gpgme.i
+++ b/gpgme.i
@@ -71,14 +71,14 @@
 
 /* Likewise for a list of strings.  */
 %typemap(in) const char *[] (void *vector = NULL,
-                             size_t size,
+                             size_t size = 0,
                              PyObject **pyVector = NULL) {
   /* Check if is a list */
   if (PyList_Check($input)) {
     size_t i, j;
     size = PyList_Size($input);
     $1 = (char **) (vector = malloc((size+1) * sizeof(char *)));
-    pyVector = calloc(sizeof *pyVector, size);
+    pyVector = calloc(size, sizeof *pyVector);
 
     for (i = 0; i < size; i++) {
       PyObject *o = PyList_GetItem($input,i);
@@ -319,8 +319,10 @@
   else if (PyInt_Check($input))
     $1 = PyInt_AsLong($input);
 #endif
-  else
+  else {
     PyErr_SetString(PyExc_TypeError, "Numeric argument expected");
+    return NULL;
+    }
 }
 
 %typemap(out) off_t {
@@ -342,8 +344,10 @@
   else if (PyInt_Check($input))
     $1 = PyInt_AsLong($input);
 #endif
-  else
+  else {
     PyErr_SetString(PyExc_TypeError, "Numeric argument expected");
+    return NULL;
+    }
 }
 
 /* Those are for gpgme_data_read() and gpgme_strerror_r().  */
diff --git a/helpers.c b/helpers.c
index 1ce7f48..50db70d 100644
--- a/helpers.c
+++ b/helpers.c
@@ -116,7 +116,8 @@ static void _gpg_stash_callback_exception(PyObject *weak_self)
     PyTuple_SetItem(excinfo, 2, Py_None);
   }
 
-  self = PyWeakref_GetObject(weak_self);
+  PyWeakref_GetRef(weak_self, &self);
+  Py_DECREF(self);
   /* self only has a borrowed reference.  */
   if (self == Py_None) {
     /* This should not happen, as even if we're called from the data
-- 
2.49.0




More information about the Gnupg-devel mailing list