Skip to content

Commit e9d781c

Browse files
Bénédikt's nits
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
1 parent f826099 commit e9d781c

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

Lib/test/test_zlib.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ def test_combine_no_iv_invalid_length(self):
183183

184184
self.assertRaises(TypeError, self.combine, 0, 0, "len")
185185
self.assertRaises(ValueError, self.combine, 0, 0, -1)
186+
self.assertRaises(OverflowError, self.combine, 0, 0, 2**1000)
187+
self.assertRaises(OverflowError, self.combine, 0, 0, -2**1000)
186188

187189
def test_combine_with_iv(self):
188190
for _ in range(self.N):
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
:func:`zlib.crc32_combine` and :func:`zlib.adler32_combine` now raise
2-
:exc:`ValueError` if the *len2* argument is negative, instead of hanging
3-
indefinitely or returning rubbish, respectively.
1+
:func:`zlib.adler32_combine` and :func:`zlib.crc32_combine` now raise
2+
:exc:`ValueError` if the *len2* argument is negative, instead of returning
3+
rubbish or hanging indefinitely, respectively.

Modules/zlibmodule.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,11 +1948,10 @@ zlib_adler32_combine_impl(PyObject *module, unsigned int adler1,
19481948
#else
19491949
z_off_t len = convert_to_z_off_t(len2);
19501950
#endif
1951-
if (PyErr_Occurred()) {
1952-
return (unsigned int)-1;
1953-
}
19541951
if (len < 0) {
1955-
PyErr_SetString(PyExc_ValueError, "len2 must be non-negative");
1952+
if (!PyErr_Occurred()) {
1953+
PyErr_SetString(PyExc_ValueError, "len2 must be non-negative");
1954+
}
19561955
return (unsigned int)-1;
19571956
}
19581957
return adler32_combine(adler1, adler2, len);
@@ -2037,11 +2036,10 @@ zlib_crc32_combine_impl(PyObject *module, unsigned int crc1,
20372036
#else
20382037
z_off_t len = convert_to_z_off_t(len2);
20392038
#endif
2040-
if (PyErr_Occurred()) {
2041-
return (unsigned int)-1;
2042-
}
20432039
if (len < 0) {
2044-
PyErr_SetString(PyExc_ValueError, "len2 must be non-negative");
2040+
if (!PyErr_Occurred()) {
2041+
PyErr_SetString(PyExc_ValueError, "len2 must be non-negative");
2042+
}
20452043
return (unsigned int)-1;
20462044
}
20472045
return crc32_combine(crc1, crc2, len);

0 commit comments

Comments
 (0)