Commit a5aa985
authored
[pointer] Fix bug in
Previously, `Ptr::try_cast_into_no_leftover` used the following logic to
recover the original `Ptr` in the case of failure:
```rust
match self.try_cast_into(CastType::Prefix, meta) {
Ok((slf, remainder)) => {
if remainder.len() == 0 {
Ok(slf)
} else {
// Undo the cast so we can return the original bytes.
let slf = slf.as_bytes();
```
This is incorrect: In the case that `remainder.len() > 0`, `slf` no
longer refers to the same referent as it did originally, as there are
remainder bytes (either in the prefix or the suffix). In this commit, we
use `Ptr::try_with` to restore the original `Ptr` exactly.
gherrit-pr-id: G27c254ea62bb8b789e4fcd4a2e9e09a74676b45atry_cast_into_no_leftover (#2937)1 parent d161a87 commit a5aa985
1 file changed
+25
-23
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1162 | 1162 | | |
1163 | 1163 | | |
1164 | 1164 | | |
1165 | | - | |
1166 | | - | |
1167 | | - | |
1168 | | - | |
1169 | | - | |
1170 | | - | |
1171 | | - | |
1172 | | - | |
1173 | | - | |
1174 | | - | |
1175 | | - | |
1176 | | - | |
1177 | | - | |
1178 | | - | |
1179 | | - | |
1180 | | - | |
1181 | | - | |
1182 | | - | |
1183 | | - | |
1184 | | - | |
1185 | | - | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
1186 | 1174 | | |
1187 | | - | |
1188 | | - | |
| 1175 | + | |
| 1176 | + | |
1189 | 1177 | | |
1190 | 1178 | | |
1191 | 1179 | | |
| |||
1523 | 1511 | | |
1524 | 1512 | | |
1525 | 1513 | | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
1526 | 1528 | | |
0 commit comments