startup-runtime: report long or truncated X2W_INPUT_SCRIPT values instead of dropping them #1852
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1859"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-24T19:42:13Z.
Change
X2W_INPUT_SCRIPT=<mask hex>@<second>[,...]drives timed presses of the GameInput stand-in's virtual gamepad. The stand-in read the value into a 512-byte buffer and kept at most 32 entries, both silently:GetEnvironmentVariableAreturns the required size when the buffer is too small and leaves its contents undefined; here the zero-initialized buffer stayed empty, so no entry ran;A longer unattended script could therefore lose all of its presses, or its later ones, without any diagnostic.
src/startup_stubs/gameinput.cppnow reads up to 4,095 characters and keeps up to 256 entries. A longer value is still ignored, but logged (x2w-input X2W_INPUT_SCRIPT ignored: N characters, at most 4095), and dropped or malformed entries are logged with their counts. Scripts that worked before (at most 32 entries, under 512 characters) parse exactly as before. Thedocs/startup-runtime.mdswitch row states the limits.Verification
On
e8b3a510(based onmainat106555ab), Windows 11 build 26300, MSVC 14.44.35207:All four pass.
tests/startup_gameinput_script.cpploads the built stand-in, sets a script whose last entry presses D-pad right (200@0) after filler entries due at second 9000, and checks that a gamepad reading within the first 200 ms has bit0x200set and that it is clear again after 0.6 s. It runs in two modes:long: 41 entries, 725 characters;entries: 33 entries, 229 characters.Measured by rebuilding the stand-in with each variant of
gameinput.cpp:gameinput.cpplongentriesmainSo each old limit is caught on its own: the buffer by
long, the entry limit byentries.Evidence and follow-up
tests/startup_gameinput_script.cpp, MIT) and needs no title or package.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:46:13Z.
Review: COMMENTED
Reviewed head
e8b3a510de834f93f175918dfe2305595129e20b.Linux checks in a clean worktree:
git diff --check origin/main...HEAD: clean (rc 0)python -B tests/docs_links_check.py: rc 0python -B tests/bidi_controls_check.py: rc 0The C++ tests in this PR are Windows-only. I could not build or run them here, so the rest is source analysis. Win2025 results are still needed.
Findings: 0 P1, 0 P2.
What I checked in
src/startup_stubs/gameinput.cpp:GetEnvironmentVariableAreturns the required size, including the terminator, when the buffer is too small. Solength >= sizeof(text)is the right overflow test. A value of exactly 4,095 characters is accepted, which matches the docs.strtokpath.strtokmodifies it, sostatic char text[4096]inside the one-time initializer is fine: the lambda runs once and thread-safely, and the buffer is not used afterwards.max_entriesis a static constexpr local, so using it for the array bounds, the loop and the log argument needs no capture.Nits, no change required:
check_scriptneeds the first read to land within 200 ms and the press to end by 600 ms. A heavily loaded runner could make that flaky.RUN_SERIALalready limits the risk.AI-assisted; commands listed were executed locally.