Skip to content

Commit a23e751

Browse files
committed
Panic when advance_slices()'ing too far.
1 parent 6045c34 commit a23e751

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

library/std/src/io/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,9 @@ impl<'a> IoSliceMut<'a> {
11551155
}
11561156

11571157
*bufs = &mut replace(bufs, &mut [])[remove..];
1158-
if !bufs.is_empty() {
1158+
if bufs.is_empty() {
1159+
assert!(n == accumulated_len, "advancing io slices beyond their length");
1160+
} else {
11591161
bufs[0].advance(n - accumulated_len)
11601162
}
11611163
}
@@ -1289,7 +1291,9 @@ impl<'a> IoSlice<'a> {
12891291
}
12901292

12911293
*bufs = &mut replace(bufs, &mut [])[remove..];
1292-
if !bufs.is_empty() {
1294+
if bufs.is_empty() {
1295+
assert!(n == accumulated_len, "advancing io slices beyond their length");
1296+
} else {
12931297
bufs[0].advance(n - accumulated_len)
12941298
}
12951299
}

0 commit comments

Comments
 (0)