[glom] Avoid some null pointer dereferences.



commit 37884d41b742c80d6722d0137e8abd0fc99a332e
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Dec 5 12:07:26 2014 +0100

    Avoid some null pointer dereferences.
    
    Found by clang's scan-build.

 glom/test_pyembed.cc                     |    5 +++--
 tests/test_selfhosting_new_then_image.cc |    6 ++++++
 2 files changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/glom/test_pyembed.cc b/glom/test_pyembed.cc
index 7c6d6b8..bc8182b 100644
--- a/glom/test_pyembed.cc
+++ b/glom/test_pyembed.cc
@@ -78,11 +78,12 @@ void evaluate_function_implementation(const Glib::ustring& func_impl)
           PyObject* pyStr = PyUnicode_AsEncodedString(pyStringObject, "utf-8", "Error ~");
           const char* pchResult = PyBytes_AS_STRING(pyStr);
           if(pchResult)
+          {
             g_warning("result is %s", pchResult);
+            Py_DECREF(pyStr);
+          }
           else
             g_warning("pchResult is null");
-
-          Py_DECREF(pyStr);
         }
         else
           g_warning("PyString_Check returned false");
diff --git a/tests/test_selfhosting_new_then_image.cc b/tests/test_selfhosting_new_then_image.cc
index 6ca7f54..b24f78e 100644
--- a/tests/test_selfhosting_new_then_image.cc
+++ b/tests/test_selfhosting_new_then_image.cc
@@ -125,6 +125,12 @@ static bool test(Glom::Document::HostingMode hosting_mode)
     binary_read = &(blob->data);
   }
 
+  if(!binary_read)
+  {
+    std::cerr << G_STRFUNC << ": Failure: The value read's data was null." << std::endl;
+    return false;
+  }
+
   const GdaBinary* binary_set = gda_value_get_binary(value_set.gobj());
   if(!binary_set)
   {


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