fix(libc): clear exhausted strtok continuation state #4625
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4625"
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 boykopovar/AnyPS5. Originally posted by QRMOE on 2026-10-12T17:02:37Z.
What
Clear the continuation pointer when
strtok_rexhausts its input, matching FreeBSD 11.4__strtok_r. Current main retains a pointer to the final NUL; modifying that old terminator can make a later continuation call resume an exhausted tokenization. The sharedstrtokwrapper receives the same correction.The regression covers final tokens, trailing separators, empty and separator-only inputs, interleaved tokenizations, changed old terminators, and errno preservation.
Tested
Windows, MinGW GCC 15.2, Release,
BUILD_TESTING=ON:libstarget passed.guest_strings,guest_wide_strings,guest_memrchr,guest_errors, andguest_collate: 5/5 passed; each finished below one second.strtok_r retained the state after exhausting delimiters.strtok_randstrtokagainst the original FreeBSD 11.4 routines at-O0and-O3: 171,717 tokenization sequences and 1,953,208 calls per optimization, including changing delimiters, buffer mutations, continuation offsets, and errno. No mismatches.git diff --checkpassed. No game testing or console-hardware validation claimed.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T14:50:37Z.
Checked the change against FreeBSD 11.4
__strtok_r(state cleared on exhaustion, also when the last token ends at the NUL).guest_stringspasses with the PR and fails on main without the fix; scoped ctest (94 tests) green. Merging once the full build is green.