ucrt: a failed memmove_s leaves the destination unmodified #96

Manually merged
github merged 1 commit from github-bot/gh-96 into main 2026-11-26 15:27:57 +00:00 AGit
Owner

@⁠Olima34 on GitHub · 2026-11-26 14:29 UTC · original
Olima34:fix/ucrt-memmove-s-keeps-destination → main · +30 −3 · 1 files · 2 commits · merged 2026-11-26 15:26 UTC

What this changes

memmove_s handed its errors to memcpy_s, which zeroes the destination for a null source or a destination too small. Microsoft's memmove_s reference lists "not modified" for all three error cases (null destination, null source, too small), unlike memcpy_s, so it now returns EINVAL or ERANGE itself and leaves the destination as it was. A count of 0 is still a success. New test memmove_s_leaves_the_destination_alone_on_error_and_memcpy_s_zeroes_it (it also pins memcpy_s's zeroing and an overlapping move).

How it was tested

  • cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory (all pass); the new test fails on main
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings, also with --all-features; clippy for x86_64-apple-darwin reports nothing in the file touched
  • arm64 cargo test --workspace and cargo xtask policy
  • Ran the game: not done, no copy of it here

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md
  • New diagnostics are behind a VICTORY_* variable and documented (none added)
**@⁠Olima34** on GitHub · 2026-11-26 14:29 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/96) `Olima34:fix/ucrt-memmove-s-keeps-destination` → `main` · +30 −3 · 1 files · 2 commits · merged 2026-11-26 15:26 UTC ## What this changes `memmove_s` handed its errors to `memcpy_s`, which zeroes the destination for a null source or a destination too small. [Microsoft's `memmove_s` reference](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/memmove-s-wmemmove-s) lists "not modified" for all three error cases (null destination, null source, too small), unlike [`memcpy_s`](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/memcpy-s-wmemcpy-s), so it now returns `EINVAL` or `ERANGE` itself and leaves the destination as it was. A count of 0 is still a success. New test `memmove_s_leaves_the_destination_alone_on_error_and_memcpy_s_zeroes_it` (it also pins `memcpy_s`'s zeroing and an overlapping move). ## How it was tested - [x] `cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory` (all pass); the new test fails on `main` - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings`, also with `--all-features`; clippy for `x86_64-apple-darwin` reports nothing in the file touched - [x] arm64 `cargo test --workspace` and `cargo xtask policy` - [ ] Ran the game: not done, no copy of it here ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md - [x] New diagnostics are behind a `VICTORY_*` variable and documented (none added)
memmove_s handed its errors to memcpy_s, which zeroes the destination for a null source or a destination too small. Microsoft's memmove_s reference lists 'not modified' for all three error cases (null destination, null source, too small), unlike memcpy_s, so it now returns EINVAL or ERANGE itself and leaves the destination as it was. A count of 0 is still a success.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:45:54 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 14:55 UTC · original · approved these changes

memmove_s leaves the destination untouched on error, as documented, and memcpy_s zeroing is pinned in the test. Thanks.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 14:55 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/96#pullrequestreview-6076266017) · **approved these changes** memmove_s leaves the destination untouched on error, as documented, and memcpy_s zeroing is pinned in the test. Thanks.
github manually merged commit 998fb72212 into main 2026-11-26 15:27:57 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.