STINNER Victor added the comment: To access an array item, the type of the index variable must be size_t (or a type with the same size), otherwise the compiler produce less efficient machine code: http://www.viva64.com/en/a/0050/
=> please keep Py_ssize_t type for i (I didn't check for the specific case of Py_ssize_t: it's signed. Does GCC emit the most efficient machine code for it?) diff -r 16c8278c03f6 Modules/_pickle.c --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -4606,10 +4606,17 @@ static Py_ssize_t calc_binsize(char *bytes, int nbytes) { unsigned char *s = (unsigned char *)bytes; - Py_ssize_t i; + int i; size_t x = 0; - for (i = 0; i < nbytes && (size_t)i < sizeof(size_t); i++) { + if (nbytes > (int)sizeof(size_t)) { + for (i = (int)sizeof(size_t); i < nbytes; i++) { + if (s[i]) + return -1; + } + nbytes = (int)sizeof(size_t); + } Please add a comment here to explain that the first loop check for integer overflow, it's not obvious at the first read. Does the Python implementation of pickle produce BINBYTES8? If not: why not? Note: the patch is probably based on a private Mercurial revision, so it didn't get the [Review] button. ---------- nosy: +haypo _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue25262> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com