about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2023-05-18 11:29:19 +0200
committerLukas Wirth <lukastw97@gmail.com>2023-05-18 11:29:19 +0200
commiteab295cc73a876eeaa1424b3ed7a76bcf46a5fec (patch)
tree84321f166b7cc514d5722ae759d9ae54599eaaee
parent4b577e2bc847a791d87634b011856cd835d75947 (diff)
downloadrust-eab295cc73a876eeaa1424b3ed7a76bcf46a5fec.tar.gz
rust-eab295cc73a876eeaa1424b3ed7a76bcf46a5fec.zip
Fix mir CString lowering not respecting the extra 0 byte for length calc
-rw-r--r--crates/hir-ty/src/mir/lower.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/crates/hir-ty/src/mir/lower.rs b/crates/hir-ty/src/mir/lower.rs
index 051ae228e22..28305bbe81c 100644
--- a/crates/hir-ty/src/mir/lower.rs
+++ b/crates/hir-ty/src/mir/lower.rs
@@ -1121,11 +1121,13 @@ impl<'ctx> MirLowerCtx<'ctx> {
             }
             hir_def::hir::Literal::CString(b) => {
                 let b = b.as_bytes();
+                let bytes = b.iter().copied().chain(iter::once(0)).collect::<Vec<_>>();
+
                 let mut data = Vec::with_capacity(mem::size_of::<usize>() * 2);
                 data.extend(0usize.to_le_bytes());
-                data.extend(b.len().to_le_bytes());
+                data.extend(bytes.len().to_le_bytes());
                 let mut mm = MemoryMap::default();
-                mm.insert(0, b.iter().copied().chain(iter::once(0)).collect::<Vec<_>>());
+                mm.insert(0, bytes);
                 return Ok(Operand::from_concrete_const(data, mm, ty));
             }
             hir_def::hir::Literal::ByteString(b) => {