mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 03:04:38 +08:00
Fix new bytes with overflow error
This commit is contained in:
1 parent
c7467e444d
commit
aa36a944bf
2 files changed
+13
-4
No files matched your search
@@ -157,7 +157,6 @@ class BaseBytesTest:
|
||||
|
||||
self.assertEqual(self.type2test(B(b"foobar")), b"foobar")
|
||||
|
||||
@unittest.skip("TODO: RUSTPYTHON")
|
||||
def test_from_ssize(self):
|
||||
self.assertEqual(self.type2test(0), b'')
|
||||
self.assertEqual(self.type2test(1), b'\x00')
|
||||
|
||||
@@ -82,9 +82,19 @@ impl ByteInnerNewOptions {
|
||||
let value = if let OptionalArg::Present(ival) = self.val_option {
|
||||
match_class!(match ival.clone() {
|
||||
i @ PyInt => {
|
||||
let size = objint::get_value(&i.into_object())
|
||||
.to_usize()
|
||||
.ok_or_else(|| vm.new_value_error("negative count".to_owned()))?;
|
||||
let size =
|
||||
objint::get_value(&i.into_object())
|
||||
.to_isize()
|
||||
.ok_or_else(|| {
|
||||
vm.new_overflow_error(
|
||||
"cannot fit 'int' into an index-sized integer".to_owned(),
|
||||
)
|
||||
})?;
|
||||
let size = if size < 0 {
|
||||
return Err(vm.new_value_error("negative count".to_owned()));
|
||||
} else {
|
||||
size as usize
|
||||
};
|
||||
Ok(vec![0; size])
|
||||
}
|
||||
_l @ PyString => {
|
||||
|
||||
Reference in new issue
Block a user