]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
The new {b,l}p_{u,}longlong() didn't check get_pylong()'s return for NULL.
authorTim Peters <tim.peters@gmail.com>
Wed, 13 Jun 2001 01:26:35 +0000 (01:26 +0000)
committerTim Peters <tim.peters@gmail.com>
Wed, 13 Jun 2001 01:26:35 +0000 (01:26 +0000)
Repaired that, and added appropriate tests for it to test_struct.py.

Lib/test/test_struct.py
Modules/structmodule.c

index e6c8bb24c69ee49eb94c3905f150c6d1bbff0507..31f4dd75d7c5b151198165b4d9a0428b83c373ed 100644 (file)
@@ -314,4 +314,10 @@ def test_std_qQ():
                     pass
                 test_one_qQ(x)
 
+    # Some error cases.
+    for direction in "<>":
+        for letter in "qQ":
+            for badobject in "a string", 3+42j, randrange:
+                any_err(struct.pack, direction + letter, badobject)
+    
 test_std_qQ()
index 4a8886f8be9ac0e132e79187775c677122e36605..66b3ac31d9f45cf742ff0bf4dce9928445713a6b 100644 (file)
@@ -874,6 +874,8 @@ bp_longlong(char *p, PyObject *v, const formatdef *f)
 {
        int res;
        v = get_pylong(v);
+       if (v == NULL)
+               return -1;
        res = _PyLong_AsByteArray((PyLongObject *)v,
                                  (unsigned char *)p,
                                  8,
@@ -888,6 +890,8 @@ bp_ulonglong(char *p, PyObject *v, const formatdef *f)
 {
        int res;
        v = get_pylong(v);
+       if (v == NULL)
+               return -1;
        res = _PyLong_AsByteArray((PyLongObject *)v,
                                  (unsigned char *)p,
                                  8,
@@ -1036,6 +1040,8 @@ lp_longlong(char *p, PyObject *v, const formatdef *f)
 {
        int res;
        v = get_pylong(v);
+       if (v == NULL)
+               return -1;
        res = _PyLong_AsByteArray((PyLongObject*)v,
                                  (unsigned char *)p,
                                  8,
@@ -1050,6 +1056,8 @@ lp_ulonglong(char *p, PyObject *v, const formatdef *f)
 {
        int res;
        v = get_pylong(v);
+       if (v == NULL)
+               return -1;
        res = _PyLong_AsByteArray((PyLongObject*)v,
                                  (unsigned char *)p,
                                  8,