[dia] [scan-build] Dereference of null pointer (maybe)



commit 26237422fee3d44b35415ba5b87a831b3de57d6e
Author: Hans Breuer <hans breuer org>
Date:   Mon Jun 9 10:08:20 2014 +0200

    [scan-build] Dereference of null pointer (maybe)
    
    The error handling for image conversion to string was a bit
    suspiciuous. Not sure if encoding could ever fail, but now
    we don't try to access a null error than.

 plug-ins/python/pydia-image.c |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)
---
diff --git a/plug-ins/python/pydia-image.c b/plug-ins/python/pydia-image.c
index 204f98b..3f77e3a 100644
--- a/plug-ins/python/pydia-image.c
+++ b/plug-ins/python/pydia-image.c
@@ -95,17 +95,23 @@ PyDiaImage_GetAttr(PyDiaImage *self, gchar *attr)
       s = g_filename_to_uri(fname, NULL, &error);
     } else {
       gchar *b64 = pixbuf_encode_base64 (dia_image_pixbuf (self->image));
-      s = g_strdup_printf ("data:image/png;base64,%s", b64);
+      if (b64)
+       s = g_strdup_printf ("data:image/png;base64,%s", b64);
+      else
+       s = NULL;
       g_free (b64);
     }
     if (s) {
       PyObject* py_s = PyString_FromString(s);
       g_free(s);
       return py_s;
-    }
-    else {
-      PyErr_SetString(PyExc_RuntimeError, error->message);
-      g_error_free (error);
+    } else {
+      if (error) {
+       PyErr_SetString(PyExc_RuntimeError, error->message);
+       g_error_free (error);
+      } else {
+       PyErr_SetString(PyExc_RuntimeError, "Pixbuf conversion failed?");
+      }
       return NULL;
     }
   }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]