improve some Negative_Read/Negative_Write logic

Returns the actual error if one is set, instead of swallowing it for the
less descriptive negative error.

Also fixes a out-of-bounds slice error in `bufio.writer_write` because
it wasn't checking the returned `m`.
This commit is contained in:
Laytan Laats
2024-04-25 19:08:48 +02:00
parent e3d41f0a9e
commit d3bd1c2110
3 changed files with 9 additions and 5 deletions
+1 -1
View File
@@ -359,7 +359,7 @@ buffer_read_from :: proc(b: ^Buffer, r: io.Reader) -> (n: i64, err: io.Error) #n
resize(&b.buf, i)
m, e := io.read(r, b.buf[i:cap(b.buf)])
if m < 0 {
err = .Negative_Read
err = e if e != nil else .Negative_Read
return
}