Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9f754e0

Browse files
committed
In b_setitem(), instead of the platform dependent CHAR_MIN and
CHAR_MAX, use hardcoded -128 and 127. This may seem strange, unless you realize that we're talking about signed bytes here! Bytes are always 8 bits and 2's complement. CHAR_MIN and CHAR_MAX are properties of the char data type, which is guaranteed to hold at least 8 bits anyway. Otherwise you'd get failing tests on platforms where unsigned char is the default (e.g. AIX). Thanks, Vladimir Marangozov, for finding this nit!
1 parent 973e4dc commit 9f754e0

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

Modules/arraymodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ b_setitem(ap, i, v)
9999
the overflow checking */
100100
if (!PyArg_Parse(v, "h;array item must be integer", &x))
101101
return -1;
102-
else if (x < CHAR_MIN) {
102+
else if (x < -128) {
103103
PyErr_SetString(PyExc_OverflowError,
104104
"signed char is less than minimum");
105105
return -1;
106106
}
107-
else if (x > CHAR_MAX) {
107+
else if (x > 127) {
108108
PyErr_SetString(PyExc_OverflowError,
109109
"signed char is greater than maximum");
110110
return -1;

0 commit comments

Comments
 (0)