Skip to content

Commit aa5eba9

Browse files
committed
fix BufferedMixin::tell
1 parent c2cd883 commit aa5eba9

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

vm/src/stdlib/io.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,8 @@ mod _io {
244244

245245
fn write(&mut self, data: &[u8]) -> Option<u64> {
246246
let length = data.len();
247-
248-
match self.cursor.write_all(data) {
249-
Ok(_) => Some(length as u64),
250-
Err(_) => None,
251-
}
247+
self.cursor.write_all(data).ok()?;
248+
Some(length as u64)
252249
}
253250

254251
//return the entire contents of the underlying
@@ -891,7 +888,8 @@ mod _io {
891888
}
892889

893890
fn raw_tell(&mut self, vm: &VirtualMachine) -> PyResult<Offset> {
894-
let ret = vm.call_method(self.check_init(vm)?, "tell", ())?;
891+
let raw = self.check_init(vm)?;
892+
let ret = vm.call_method(raw, "tell", ())?;
895893
let offset = get_offset(ret, vm)?;
896894
if offset < 0 {
897895
return Err(
@@ -1474,7 +1472,14 @@ mod _io {
14741472
#[pymethod]
14751473
fn tell(&self, vm: &VirtualMachine) -> PyResult<Offset> {
14761474
let mut data = self.lock(vm)?;
1477-
Ok(data.raw_tell(vm)? - data.raw_offset())
1475+
let raw_tell = data.raw_tell(vm)?;
1476+
let raw_offset = data.raw_offset();
1477+
let mut pos = raw_tell - raw_offset;
1478+
// GH-95782
1479+
if pos < 0 {
1480+
pos = 0;
1481+
}
1482+
Ok(pos)
14781483
}
14791484
#[pymethod]
14801485
fn truncate(

0 commit comments

Comments
 (0)