mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Merge pull request #2387 from carbotaniuman/magic-methods
use unsigned abs to avoid overflow
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from testutils import assert_raises
|
||||
import pickle
|
||||
import sys
|
||||
|
||||
# new
|
||||
assert bytearray([1, 2, 3])
|
||||
@@ -753,4 +754,8 @@ b = pickle.loads(pickle.dumps(a, 4))
|
||||
assert type(a) == type(b)
|
||||
assert a.x == b.x
|
||||
assert a.y == b.y
|
||||
assert a == b
|
||||
assert a == b
|
||||
|
||||
a = bytearray()
|
||||
for i in range(-1, 2, 1):
|
||||
assert_raises(IndexError, lambda: a[-sys.maxsize - i], _msg='bytearray index out of range')
|
||||
@@ -391,7 +391,7 @@ impl TryFromObject for SequenceIndex {
|
||||
// Use PySliceableSequence::wrap_index for implementors
|
||||
pub(crate) fn wrap_index(p: isize, len: usize) -> Option<usize> {
|
||||
let neg = p.is_negative();
|
||||
let p = p.abs().to_usize()?;
|
||||
let p = p.wrapping_abs() as usize;
|
||||
if neg {
|
||||
len.checked_sub(p)
|
||||
} else if p >= len {
|
||||
|
||||
Reference in New Issue
Block a user