about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChris Denton <christophersdenton@gmail.com>2022-03-09 00:47:24 +0000
committerChris Denton <christophersdenton@gmail.com>2022-03-09 01:05:47 +0000
commit57442beb18a056f4ec098812a941393cdc67bbee (patch)
tree1c3dcfd1a44417cdbf6679e14def1dba91f89a17
parent1eb72580d076935a3e590deb6e5813a5aef3eca4 (diff)
downloadrust-57442beb18a056f4ec098812a941393cdc67bbee.tar.gz
rust-57442beb18a056f4ec098812a941393cdc67bbee.zip
Use `unreachable!` for an unreachable code path
-rw-r--r--library/std/src/sys/windows/mod.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/library/std/src/sys/windows/mod.rs b/library/std/src/sys/windows/mod.rs
index dc288176346..6097e628768 100644
--- a/library/std/src/sys/windows/mod.rs
+++ b/library/std/src/sys/windows/mod.rs
@@ -224,8 +224,14 @@ where
             } as usize;
             if k == n && c::GetLastError() == c::ERROR_INSUFFICIENT_BUFFER {
                 n *= 2;
-            } else if k >= n {
+            } else if k > n {
                 n = k;
+            } else if k == n {
+                // It is impossible to reach this point.
+                // On success, k is the returned string length excluding the null.
+                // On failure, k is the required buffer length including the null.
+                // Therefore k never equals n.
+                unreachable!();
             } else {
                 return Ok(f2(&buf[..k]));
             }