Skip to content

base_reservation: read LEONIDA_BASE_RESERVED with swscanf_s (MSVC C4996), with a parse test - #1942

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
etcetera-yt:base-reservation-swscanf-s
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
etcetera-yt:base-reservation-swscanf-s

Conversation

@etcetera-yt

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: new BUILD item, MSVC C4996 (swscanf) in runtime/src/base_reservation.h (claim)

What and why

std::swscanf at runtime/src/base_reservation.h:44 (from d820ecf, RT-22) was the runtime build's only warning on main 6a6704d:

runtime\src\base_reservation.h(44,14): warning C4996: 'swscanf': This function or variable may be unsafe. Consider using swscanf_s instead.

The build printed it 6 times across 5 targets (gta6rt, loader_test, loader_tls_test, pe_loader_test, test_pe_loader_bounds). This PR uses swscanf_s. For integer conversions such as %llx it takes no buffer-size arguments, so the %llx:%llx parse is unchanged. The runtime builds only with MSVC or clang-cl, and both have swscanf_s in the UCRT.

pe_loader_test now also checks rt::base_reservation::inherited():

  • 140000000:30000000 gives base 0x140000000 and size 0x30000000;
  • size 0, no size, a non-hex base, and no variable all give no reservation.

Only arm64 Wine relaunches gta6rt, so before this no Windows run reached that parser. The test restores the variable afterwards.

#1707 (@ashiikins, RT-22) still has the same line. This PR changes only that call, so it doesn't overlap 427532c's changes.

Nothing is left for this item.

Tested

NVIDIA GeForce RTX 5060 Ti, driver 621.14, Windows 10 19045. VS 2022 BuildTools (MSVC), Vulkan SDK 1.4.363.0.

cmake -S runtime -B runtime/build
cmake --build runtime/build --config RelWithDebInfo -- -m:2
ctest --test-dir runtime/build -C RelWithDebInfo --output-on-failure
LEONIDA_VK_VALIDATION=1 ctest --test-dir runtime/build -C RelWithDebInfo --output-on-failure
main 6a6704d this PR 74941a24
build warnings 6 (all this C4996) 0
ctest 107/109, 7 skipped; d3d12_compute, d3d12_draw fail same
ctest, validation on 107/109, 6 skipped; same two fail, 1 VUID (vkDestroyPipeline, in d3d12_draw) same
pe_loader OK (74 checks) OK (79 checks)

Both failures are on the known-failures list and are unrelated to this PR: d3d12_draw (fence 21 after 30, fixed by #1807) and d3d12_compute line 515 (device_proxy_ref_count, fixed by #1898/#1919).

Negative control: with the format changed to %llx;%llx, pe_loader fails LEONIDA_BASE_RESERVED=140000000:30000000 is base 0x140000000, size 0x30000000 (79 checks, 1 failure). With the format restored it passes.

Not tested: the arm64 Wine / CrossOver relaunch itself (run_tiny_game_fixed passes here, but on Windows the range is free, so it doesn't relaunch); a clang-cl/xwin cross build; the Python test suite (no Python changed).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

AI-assisted (Claude Code).

🤖 Generated with Claude Code

swscanf at base_reservation.h:44 was the runtime build's only warning on
main 6a6704d, printed for five targets. swscanf_s takes no buffer sizes
for integer conversions, so the %llx:%llx parse is the same.

pe_loader_test now checks inherited(): a valid value, size 0, no size,
a non-hex base and no variable. Only arm64 Wine relaunches gta6rt, so a
Windows run never reached this parser before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@UNYTIX

UNYTIX commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Independent Windows check of 74941a2411c89a9686b23ee8342f744a7807b77f on Windows 11 26H2, VS 2022 17.14.45 (MSVC 14.44) and Windows SDK 10.0.26100.0. I built a standalone probe of base_reservation::inherited() with cl /nologo /EHsc /std:c++20 /W4 /we4996 /I runtime\src parser_probe.cpp. The PR header built cleanly. The same command on base 6a6704df failed with C4996 at base_reservation.h:44.

All seven parser cases passed on the PR and on the base when built with /wd4996. The cases cover two valid ranges (including a size above 32 bits), zero size, missing size, a nonhex base, an unset variable, and an overlong marker. This exercised only the parser, using process-local synthetic values. CPU-only, AI-assisted.

@matheuskshn

Copy link
Copy Markdown
Contributor

Independent Windows 11 check of 74941a2 with native Clang 23.1.5 (MSYS2 CLANG64/UCRT). I compiled a standalone probe of base_reservation::inherited() against the PR header and base 6a6704d. Both passed all 10 cases with identical behavior. Beyond the new regression cases, this covers an empty value, a trailing colon without a size, a maximum 64-bit base, and the environment buffer boundary (valid at 63 characters, skipped at 64). Parser only. AI-assisted.

@etcetera-yt

Copy link
Copy Markdown
Contributor Author

Thanks @UNYTIX and @matheuskshn for the independent checks (MSVC with /we4996 and Clang/UCRT, including the extra edge cases). AI-assisted (Claude Code).

@Jadiac5

Jadiac5 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 74941a24 on Windows 11, MSVC 19.44.35222 (VS 2022 Build Tools, Ninja, RelWithDebInfo): pass.

  • Ran: full runtime build and ctest --test-dir runtime/build -C RelWithDebInfo --output-on-failure (a whole-tree build, on top of the two
    standalone checks already here).
  • ctest: 42/42 passed, same as main at 4eb6155d. pe_loader: OK, 79 checks (main: 74).
  • The C4996 swscanf warning at runtime/src/base_reservation.h:44 is gone: main prints it for each target that
    includes the header, this branch for none.
  • Code read: no concerns. test_inherited_reservation does not restore a saved value longer than 63 characters, which
    does not matter for a test process.
  • Note: the branch is based on 6a6704df, not current main; I tested the branch as it is, not a merge.

AI-assisted (Claude Code).

@etcetera-yt

Copy link
Copy Markdown
Contributor Author

Thanks @Jadiac5 for the whole-tree build and ctest run. AI-assisted (Claude Code).

@ItsNotRexed
ItsNotRexed merged commit 6a4eff5 into ItsNotRexed:main Nov 22, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants