about summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2022-03-11 17:25:04 +0100
committerMara Bos <m-ou.se@m-ou.se>2022-03-11 17:29:53 +0100
commita23e7513fa530d9013ca2dd67ad0e0ffb16aa16f (patch)
treee2f6237283468a7ade0fab30ffd71e4880d8b897 /library/std/src
parent6045c34f15d463c7d51104b968c1eabc5275b9c1 (diff)
downloadrust-a23e7513fa530d9013ca2dd67ad0e0ffb16aa16f.tar.gz
rust-a23e7513fa530d9013ca2dd67ad0e0ffb16aa16f.zip
Panic when advance_slices()'ing too far.
Diffstat (limited to 'library/std/src')
-rw-r--r--library/std/src/io/mod.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs
index 3fa965d08e6..47be2c504ed 100644
--- a/library/std/src/io/mod.rs
+++ b/library/std/src/io/mod.rs
@@ -1155,7 +1155,9 @@ impl<'a> IoSliceMut<'a> {
         }
 
         *bufs = &mut replace(bufs, &mut [])[remove..];
-        if !bufs.is_empty() {
+        if bufs.is_empty() {
+            assert!(n == accumulated_len, "advancing io slices beyond their length");
+        } else {
             bufs[0].advance(n - accumulated_len)
         }
     }
@@ -1289,7 +1291,9 @@ impl<'a> IoSlice<'a> {
         }
 
         *bufs = &mut replace(bufs, &mut [])[remove..];
-        if !bufs.is_empty() {
+        if bufs.is_empty() {
+            assert!(n == accumulated_len, "advancing io slices beyond their length");
+        } else {
             bufs[0].advance(n - accumulated_len)
         }
     }