You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to the ISO C standard (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf) section 6.5.6 paragraph 8, the behavior of the C addition operator is undefined if the result of the operand does not either fall inside the same array object that is being indexed, or one index past the end of the array object. In Objects/obmalloc.c line 841, the macros PT(0) through PT(7) expand to references to array indexes before the beginning of the usedpools array. As a result, this initializer causes this file to be undefined.
As a result, this initializer causes this file to be undefined.
Hum, in practice I'm not aware of any crash on any platform. Python is tested on various compilers (GCC, Clang, ICC, Microsoft Visual Studio, etc.), various operating systems (Mac OS X, Linux, Windows, FreeBSD, OpenBSD, Solaris, etc.), various architectures (x86, x86-64, PPC, etc.).
The memory allocator is probably the first instruction when starting Python.
Anyway, do you see a way to avoid the undefined behaviour?
Python has a _PyMem_SetupAllocators() function called very early in main() (before the first Python memory allocation), but calling this function is optional. So we have to prepare everything during the compilation.
Python is tested by ASAN, MSAN and UBSAN, and different memory debuggers. Last years, nobody reported an issue about this code. IMO it's just fine. Moreover, no fix was proposed. I just close the issue.
Activity
dwightguth commentedon Feb 23, 2015
According to the ISO C standard (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf) section 6.5.6 paragraph 8, the behavior of the C addition operator is undefined if the result of the operand does not either fall inside the same array object that is being indexed, or one index past the end of the array object. In Objects/obmalloc.c line 841, the macros PT(0) through PT(7) expand to references to array indexes before the beginning of the usedpools array. As a result, this initializer causes this file to be undefined.
vstinner commentedon Sep 19, 2016
It seems that line numbers are for Python 3.5:
vstinner commentedon Sep 19, 2016
Hum, in practice I'm not aware of any crash on any platform. Python is tested on various compilers (GCC, Clang, ICC, Microsoft Visual Studio, etc.), various operating systems (Mac OS X, Linux, Windows, FreeBSD, OpenBSD, Solaris, etc.), various architectures (x86, x86-64, PPC, etc.).
The memory allocator is probably the first instruction when starting Python.
Anyway, do you see a way to avoid the undefined behaviour?
Python has a _PyMem_SetupAllocators() function called very early in main() (before the first Python memory allocation), but calling this function is optional. So we have to prepare everything during the compilation.
iritkatriel commentedon Feb 12, 2023
These macros have now been moved to https://github.com/python/cpython/blob/main/Include/internal/pycore_obmalloc_init.h
vstinner commentedon Apr 5, 2023
Python is tested by ASAN, MSAN and UBSAN, and different memory debuggers. Last years, nobody reported an issue about this code. IMO it's just fine. Moreover, no fix was proposed. I just close the issue.