]> git.lizzy.rs Git - rust.git/commit - src/tools/miri
Auto merge of #97053 - CAD97:realloc-clarification, r=dtolnay
authorbors <bors@rust-lang.org>
Mon, 16 May 2022 02:33:34 +0000 (02:33 +0000)
committerbors <bors@rust-lang.org>
Mon, 16 May 2022 02:33:34 +0000 (02:33 +0000)
commit56d540e0571ac1b0633ce10644224c495aaf42a0
treefc6b28edf61020b4855fd6a34efe65cc42b60c47
parentcdd74fc7b19805c65c7d6f759ec6871be1c38fce
parent09dc24bc04ed162b92790195f2f84bc674cc3025
Auto merge of #97053 - CAD97:realloc-clarification, r=dtolnay

Remove potentially misleading realloc parenthetical

This parenthetical is problematic, because it suggests that the following is sound:

```rust
let layout = Layout::new::<[u8; 32]>();
let p1 = alloc(layout);
let p2 = realloc(p1, layout, 32);
if p1 == p2 {
    p1.write([0; 32]);
    dealloc(p1, layout);
} else {
    dealloc(p2, layout);
}
```

At the very least, this isn't the case for [ANSI `realloc`](https://en.cppreference.com/w/c/memory/realloc)

> The original pointer `ptr` is invalidated and any access to it is undefined behavior (even if reallocation was in-place).

and [Windows `HeapReAlloc`](https://docs.microsoft.com/en-us/windows/win32/api/heapapi/nf-heapapi-heaprealloc) is unclear at best (`HEAP_REALLOC_IN_PLACE_ONLY`'s description may imply that the old pointer may be used if `HEAP_REALLOC_IN_PLACE_ONLY` is provided).

The conservative position is to just remove the parenthetical.

cc `@rust-lang/wg-unsafe-code-guidelines` `@rust-lang/wg-allocators`