Closed elihunter173 closed 4 months ago
The current construct_fake_string() layout determination code is wrong (but luckily works when the layout is [ptr, cap, len]!)
construct_fake_string()
[ptr, cap, len]
Suppose the real layout is [len, ptr, cap]. Then
[len, ptr, cap]
sentinel_string.as_ptr() as usize == 1 sentinel_string.capacity() == 2 sentinel_string.len() == 0
Which would cause the previous code to create a string with layout [fields[1], fields[2], fields[0]] == [cap, len, ptr] when it's supposed to create [len, ptr, cap].
[fields[1], fields[2], fields[0]] == [cap, len, ptr]
The new code would execute
actual_buf[1] = ptr; actual_buf[2] = cap; actual_buf[0] = len;
Which would correctly create a string with layout [len, ptr, cap].
Thank you for catching this!
The current
construct_fake_string()
layout determination code is wrong (but luckily works when the layout is[ptr, cap, len]
!)Suppose the real layout is
[len, ptr, cap]
. ThenWhich would cause the previous code to create a string with layout
[fields[1], fields[2], fields[0]] == [cap, len, ptr]
when it's supposed to create[len, ptr, cap]
.The new code would execute
Which would correctly create a string with layout
[len, ptr, cap]
.