Skip to content

Commit cc249d2

Browse files
committed
add missing error-checking
1 parent 6b67546 commit cc249d2

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

tests/test_pythoncapi_compat_cext.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,29 +1432,48 @@ test_long_api(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
14321432
PyLongWriter *writer;
14331433
static PyLongExport long_export;
14341434

1435-
writer = PyLongWriter_Create(1, 1, (void**)&digits);
1435+
writer = PyLongWriter_Create(1, 1, (void **)&digits);
1436+
if (writer == NULL) {
1437+
return NULL;
1438+
}
14361439
PyLongWriter_Discard(writer);
14371440

1438-
writer = PyLongWriter_Create(1, 1, (void**)&digits);
1441+
writer = PyLongWriter_Create(1, 1, (void **)&digits);
1442+
if (writer == NULL) {
1443+
return NULL;
1444+
}
14391445
digits[0] = 123;
14401446
obj = PyLongWriter_Finish(writer);
1447+
if (obj == NULL) {
1448+
return NULL;
1449+
}
14411450

14421451
check_int(obj, -123);
1443-
PyLong_Export(obj, &long_export);
1452+
if (PyLong_Export(obj, &long_export) < 0) {
1453+
return NULL;
1454+
}
14441455
assert(long_export.value == -123);
14451456
assert(long_export.digits == NULL);
14461457
PyLong_FreeExport(&long_export);
14471458
Py_DECREF(obj);
14481459

1449-
writer = PyLongWriter_Create(0, 5, (void**)&digits);
1460+
writer = PyLongWriter_Create(0, 5, (void **)&digits);
1461+
if (writer == NULL) {
1462+
return NULL;
1463+
}
14501464
digits[0] = 1;
14511465
digits[1] = 0;
14521466
digits[2] = 0;
14531467
digits[3] = 0;
14541468
digits[4] = 1;
14551469
obj = PyLongWriter_Finish(writer);
1470+
if (obj == NULL) {
1471+
return NULL;
1472+
}
14561473

1457-
PyLong_Export(obj, &long_export);
1474+
if (PyLong_Export(obj, &long_export) < 0) {
1475+
return NULL;
1476+
}
14581477
assert(long_export.value == 0);
14591478
digits = (digit*)long_export.digits;
14601479
assert(digits[0] == 1);

0 commit comments

Comments
 (0)