Fix cquoting crash with Decimal() type.
authorMarko Kreen <markokr@gmail.com>
Mon, 29 Dec 2008 16:43:27 +0000 (16:43 +0000)
committerMarko Kreen <markokr@gmail.com>
Mon, 29 Dec 2008 16:43:27 +0000 (16:43 +0000)
Seems there can be types which have buffer operations struct,
but no function pointers.  So check also for called functions.

python/modules/cquoting.c

index 42844ca2631617d71f40e02c8da845fc4094c33e..eb518a3edbf870dc4d1a523db7620b4f440c42d1 100644 (file)
@@ -130,8 +130,10 @@ static Py_ssize_t get_buffer(PyObject *obj, unsigned char **buf_p, PyObject **tm
 
        /* try to get buffer */
        bfp = obj->ob_type->tp_as_buffer;
-       if (bfp && bfp->bf_getsegcount(obj, NULL) == 1)
-               return bfp->bf_getreadbuffer(obj, 0, (void**)buf_p);
+       if (bfp && bfp->bf_getsegcount && bfp->bf_getreadbuffer) {
+               if (bfp->bf_getsegcount(obj, NULL) == 1)
+                       return bfp->bf_getreadbuffer(obj, 0, (void**)buf_p);
+       }
 
        /*
         * Not a string-like object, run str() or it.