mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Trent Mick <trentm@ActiveState.com>:
This patch correct bounds checking in PyLong_FromLongLong. Currently, it does not check properly for negative values when checking to see if the incoming value fits in a long or unsigned long. This results in possible silent truncation of the value for very large negative values.
This commit is contained in:
parent
8eded195aa
commit
4c7fdfc35b
1 changed files with 2 additions and 2 deletions
|
@ -355,10 +355,10 @@ PyLong_FromLongLong(ival)
|
||||||
/* In case the compiler is faking it. */
|
/* In case the compiler is faking it. */
|
||||||
return PyLong_FromLong( (long)ival );
|
return PyLong_FromLong( (long)ival );
|
||||||
#else
|
#else
|
||||||
if( ival <= (LONG_LONG)LONG_MAX ) {
|
if ((LONG_LONG)LONG_MIN <= ival && ival <= (LONG_LONG)LONG_MAX) {
|
||||||
return PyLong_FromLong( (long)ival );
|
return PyLong_FromLong( (long)ival );
|
||||||
}
|
}
|
||||||
else if( ival <= (unsigned LONG_LONG)ULONG_MAX ) {
|
else if (0 <= ival && ival <= (unsigned LONG_LONG)ULONG_MAX) {
|
||||||
return PyLong_FromUnsignedLong( (unsigned long)ival );
|
return PyLong_FromUnsignedLong( (unsigned long)ival );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue