[issue28215] PyModule_AddIntConstant() wraps >=2^31 values when long is 4 bytes

Kyle Altendorf report at bugs.python.org
Tue Sep 20 13:52:33 EDT 2016


Kyle Altendorf added the comment:

I do not seem to be getting a compiler warning.

arm-fsl-linux-gnueabi-gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes    -Werror=declaration-after-statement   -I. -IInclude -I./Include -I"/epc/t/262/misc-build-arm-fsl-linux-gnueabi/sysroot/root/all//opt/epc/include"   -DPy_BUILD_CORE  -c ./Modules/socketmodule.c -o Modules/socketmodule.o

To really encompass all cases I think you are correct that both a signed and an unsigned handler are needed.  Though, I have an idea for something nifty, I'll share if it works.

Regardless, shouldn't they use `intmax_t` and `uintmax_t` from stdtypes.h to make sure they handle anything that could be defined in the referenced C code?  In my case simply switching from `long` to `intmax_t` would be sufficient.

Note that I am not worried about getting this fixed for my one case.  My workaround is fine for my application.

I also will hopefully be correcting the subject to >=2**31 if this change does what I think.  Good ol' off-by-one.

----------
title: PyModule_AddIntConstant() wraps >=2^32 values when long is 4 bytes -> PyModule_AddIntConstant() wraps >=2^31 values when long is 4 bytes

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28215>
_______________________________________


More information about the Python-bugs-list mailing list