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
+4
View File
@@ -95,6 +95,10 @@ writer_write :: proc(b: ^Writer, p: []byte) -> (n: int, err: io.Error) {
m: int
if writer_buffered(b) == 0 {
m, b.err = io.write(b.wr, p)
if m < 0 && b.err == nil {
b.err = .Negative_Write
break
}
} else {
m = copy(b.buf[b.n:], p)
b.n += m