diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-06-13 01:26:35 +0000 |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-06-13 01:26:35 +0000 |
commit | a540e5be64c3b9faae44d0cbf97b2b20ba74906d (patch) | |
tree | 2b12fb737cdeb78c301020be785cdeceb331873c | |
parent | 8fe78862bfafd82be4fa808000e143c9aab18f41 (diff) | |
download | cpython-a540e5be64c3b9faae44d0cbf97b2b20ba74906d.tar.gz |
The new {b,l}p_{u,}longlong() didn't check get_pylong()'s return for NULL.
Repaired that, and added appropriate tests for it to test_struct.py.
-rw-r--r-- | Lib/test/test_struct.py | 6 | ||||
-rw-r--r-- | Modules/structmodule.c | 8 |
2 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py index e6c8bb24c6..31f4dd75d7 100644 --- a/Lib/test/test_struct.py +++ b/Lib/test/test_struct.py @@ -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() diff --git a/Modules/structmodule.c b/Modules/structmodule.c index 4a8886f8be..66b3ac31d9 100644 --- a/Modules/structmodule.c +++ b/Modules/structmodule.c @@ -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, |