Commit Graph
75 Commits
Author SHA1 Message Date
Dean a1f95a523f Merge pull request #8849 from hypermoist/fix/libc-integer-base
fix(libc): follow the console for integer bases and 0x prefixes
2026-10-21 23:46:18 +13:00
hypermistandClaude Opus 5.5 8e46144d48 fix(libc): follow the console for integer bases and 0x prefixes
- strtol, strtoul, strtoll, strtoull and strtouq return 0 for a base
  outside 0 and 2 to 36, leave the end at the start and set EINVAL;
  strtoimax, strtoumax, _Stoull, _Stoul and the wide forms do the same
  without errno.
- A 0x prefix with no hexadecimal digit after it (base 0 or 16) is no
  conversion: the end stays at the start of the string.
- wcstol, wcstoll and wcstoimax take one sign, convert the rest with
  wcstoull and clamp to the signed range with ERANGE, so "- 1" is -1
  and "+\t-1" overflows.
- atoi, atol and atoll truncate strtoull's result.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK
2026-10-21 16:05:00 +13:00
Kraken 20e95370ae feat(libc): implement index string search 2026-10-21 03:29:12 +01:00
Dean b56cfb3817 Merge pull request #8444 from SwetabhSingh17/feat/libc-mem-utilities
feat(libc): implement memmem and memccpy
2026-10-21 13:24:46 +13:00
Swetabh Singh f3dec86695 feat(libc): implement memmem and memccpy 2026-10-20 18:12:52 +05:30
hypermistandClaude Opus 5.5 b455c751bb fix(libc): leave errno alone for subnormal strtod results
The console's strtof, strtod and strtold set ERANGE only when a
conversion underflows to zero; a non-zero subnormal result leaves errno
unchanged, while the host's sets it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK
2026-10-21 00:48:05 +13:00
Adrià 6bd02dd915 Merge pull request #7545 from ionut27001/fix/libc-strtod-nan-payload
fix(libc): parse NaN payloads in strtod as measured on a PS5
2026-10-20 12:25:58 +02:00
xXPBSXxandClaude Sonnet 5.5 906b2527b8 fix(libc): convert the character argument of strrchr to char
strrchr passed its int argument to the host strrchr unchanged. On Windows the
host compares it with the signed char bytes of the string, so a byte of 0x80 to
0xFF passed as an unsigned value (0xE9) or a value above 255 (0x12F) was not
found, where FreeBSD converts the argument to char first.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-20 01:52:52 +02:00
Adrià 40d244f668 Merge pull request #6853 from DavidSamir/fix/libc-strtol-no-conversion-errno-macos
fix(libc): keep errno when strtol converts nothing on macOS
2026-10-19 14:17:55 +02:00
David 717f318e2e fix(libc): keep errno when strtol converts nothing on macOS
macOS's strtoll and strtoull set errno to EINVAL when the subject has
no digits, as in "", "words" or " +". The guest's integer conversions
pass that to the title, while guest_atoi, guest_wide_conversion and
guest_math expect errno unchanged, as glibc leaves it. So atoi("")
returned 0 with errno 22 on macOS, and all three tests failed there.

A ParseInteger helper in SonyCrt.hpp calls the host's conversion and,
on macOS, restores the caller's errno when nothing was converted and
the base is valid. An overflow still sets ERANGE, and an invalid base
still sets EINVAL. strtol, strtoul, strtoll, strtoull, atoi, atol,
atoll, _Stoull and the wcsto* integer conversions in Strings.cpp use
it. On other hosts the helper calls the conversion unchanged.
2026-10-19 12:20:32 +02:00
ShinMalphur 016f743c64 fix(libc): reject oversized secure string destinations 2026-10-19 13:11:00 +06:30
ionut27001andClaude Opus 5.5 ae662c873d fix(libc): parse NaN payloads in strtod as measured on a PS5
In a payload process on a PS5 (firmware 12.70), the strtod and wcstod
of libSceLibcInternal.sprx keep the payload of a NAN(...) sequence,
read as FreeBSD 11's gdtoa hexnan reads it, under the quiet bit and
with the sign. strtof, wcstof, strtold and wcstold return the positive
default quiet NaN whatever the sign and the sequence, and consume a
sequence of letters, digits and underscores up to its closing
parenthesis. Here every NaN lost its payload, and strtof and strtold
kept the sign.

The model reproduces the 64 NaN inputs that p11, p14, p27 and p33
measured, including blanks and other characters inside the parentheses
and unterminated sequences, and the test now pins them. It also pins
two p71 cases measured through strtod: nan(1 2), and "nan( " followed
by NUL and ")". In hexnan, a blank after a payload digit, while a
32-bit word of the payload is still free, starts a blank skip that has
no NUL check, so when only blanks follow up to the terminating NUL the
console reads past it (p71); that case throws here. A blank right after
"nan(" is skipped with a NUL check, and the console stopped at the NUL
there.

AI-assisted: yes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 09:20:41 +03:00
Adrià 676d423968 Merge pull request #6532 from ArjenS-LA/feat/guest-bcopy
feat(libc): implement overlap-safe bcopy
2026-10-19 06:09:37 +02:00
Adrià c7f67e5cf3 Merge pull request #6144 from freshstart2066-create/feat/libc-safe-wide-strings
feat(libc): implement safe wide string and concatenation functions
2026-10-18 23:26:38 +02:00
T3cm0andClaude Opus 5.5 f68ab450e2 feat(libc): implement wcscspn, wcstoimax, wcstoumax, strtouq, rindex and flsl
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 20:44:06 -05:00
ArjenS-LA af691b717a feat(libc): implement overlap-safe bcopy 2026-10-15 11:27:49 -07:00
BIGFERRY999 c33036b162 feat(libc): implement safe wide string and concatenation functions 2026-10-15 00:20:27 +01:00
Feuris 6beefccfa5 feat(libc): implement wcsnlen_s 2026-10-13 21:35:45 -03:00
Adrià 7e4edf509a Merge pull request #4616 from EagleBearerYS/fix/libc-strtod-quiet-nan-windows
fix(libc): return the default quiet NaN from the strtod family
2026-10-13 17:11:55 +02:00
Adrià 3b94f923a5 Merge pull request #4633 from QRMOE/fix-libc-wcsxfrm-truncation
fix(libc): terminate truncated wcsxfrm results
2026-10-13 17:00:13 +02:00
Feuris cd0e9dccd7 feat(libc): implement wcscat 2026-10-13 08:38:02 -03:00
Yunus Shaikh 2c0d8d48bc Merge remote-tracking branch 'origin/main' into fix/libc-strtod-quiet-nan-windows
# Conflicts:
#	docs/dev/TechnicalDebt.md
2026-10-12 11:45:40 -07:00
Dean b9f194a890 Merge pull request #4455 from SibteProf/fix/libc-secure-copy-size-limits
fix(libc): reject oversized secure copy destinations
2026-10-13 07:26:35 +13:00
Dean f30e89ee7c Merge pull request #4365 from Gashrod1/fix/libc-strxfrm-truncation
fix(libc): truncate strxfrm like FreeBSD's C locale
2026-10-13 07:20:51 +13:00
Yunus Shaikh c55f377fb0 refactor(libc): place the NaN helpers and test includes apart from neighbouring changes 2026-10-12 11:03:36 -07:00
QRMOE 22d03d497f fix(libc): terminate truncated wcsxfrm results 2026-10-12 19:03:18 +02:00
Yunus Shaikh aa4a9b4faf fix(libc): return the default quiet NaN from the strtod family
C17 7.22.1.3 and 7.29.4.1.1 interpret NAN(n-char-sequence) as a quiet
NaN. With MinGW-w64, std::strtod, strtof and strtold are mingw-w64's
gdtoa functions, which copy the hex digits into the significand
without the quiet bit, and for long double without the x87 integer
bit: strtod("nan(0x123)") returned the signaling NaN
0x7ff0000000000123 and strtold a pseudo-NaN. A payload whose only set
bit is the implicit or x87 integer bit gave infinity:
strtof("nan(0x800000)"), strtod("nan(0x10000000000000)") and
strtold("nan(0x8000000000000000)") returned +inf. glibc returns quiet
NaNs that keep the payload.

C17 7.12.11.2p2 makes nan("n-char-sequence") equivalent to
strtod("NAN(n-char-sequence)", NULL), and nan and nanf already return
the console's fixed quiet NaNs, ignoring the tag. ParseFloat, which
strtod, strtof, strtold, atof and the wide variants share, now returns
the same values, 0x7ff8000000000000 and 0x7fc00000, negated after a
minus sign, on Windows and Linux. strtold returns the x87 default
quiet NaN, since no console nanl was observed.
2026-10-12 09:04:31 -07:00
Dean 3b83f71e0f Merge pull request #3905 from aureau/aureau/carry-libc-strtod-no-conversion-zero
fix(libc): return positive zero when float parsing consumes no input
2026-10-13 02:34:59 +13:00
Dean 4bf963d660 Merge pull request #3966 from MarcZX100/codex/carry-strcasecmp-lowered
fix(libc): compare strcasecmp results after lowercasing bytes
2026-10-13 01:56:24 +13:00
SibteProf 5ffafa920f fix(libc): reject oversized secure copy destinations 2026-10-12 17:06:54 +05:00
m.peauandClaude Opus 5.5 e19e9145dd fix(libc): truncate strxfrm like FreeBSD's C locale
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-12 09:42:28 +02:00
mir 89b4b2475e Merge branch 'main' into aureau/carry-libc-strtod-no-conversion-zero 2026-10-12 01:34:06 -04:00
Adrià ca4ab0d5d6 Merge pull request #3687 from Lorkydey/fix/libc-atoi-guest-width
fix(libc): parse atoi through guest-width strtol
2026-10-11 23:51:52 +02:00
Hussein Kadhim aaf49fb40f fix(libc): compare strcasecmp and strncasecmp results after lowering
FreeBSD returns the difference of the lowercased bytes where the strings
differ, including where one of them ends. The guest wrappers returned the raw
difference of the terminator and the unfolded byte, so strcasecmp("ab", "A")
gave 66 instead of 98.
2026-10-11 19:49:35 +00:00
Hussein Kadhim 216ced6c27 fix(libc): return positive zero when strtod, strtof, strtold and wide variants perform no conversion 2026-10-11 21:51:20 +05:30
Lorkydey 6744880450 fix(libc): parse atoi through guest-width strtol 2026-10-11 17:20:39 +02:00
DariusHQ 6ef110af48 feat(libc): implement wcstok
PS5MC (PPSA99420) stops at start-up on wcstok once sendfile is in. It
follows FreeBSD's three-argument wcstok over the guest's 16-bit wchar_t:
leading delimiters are skipped, the token ends at the next delimiter,
which is overwritten with 0, and *last is set to null when the string
runs out.
2026-10-11 16:41:50 +03:00
Pouare514 5290f92876 fix(libs): share Sony CRT semantics between libc and libSceAmpr with tests 2026-10-11 11:42:31 +02:00
Adrià 379e5d8795 Merge pull request #3280 from MarcZX100/codex/libc-memset-s-freebsd-3166
fix(libc): follow FreeBSD memset_s errors
2026-10-11 09:18:14 +02:00
Fishybeing 007cc62555 fix(libc): follow FreeBSD's memset_s errors
FreeBSD's memset_s returns EINVAL for every constraint violation and writes nothing when smax or n exceeds RSIZE_MAX. The guest returned ERANGE when n exceeded smax and wrote up to min(n, smax) bytes even when smax or n exceeded RSIZE_MAX.

(cherry picked from commit bf08837cf929e40f1b646df82e140a33076d5587)
2026-10-11 05:05:02 +00:00
MarcZX100andClaude Opus 5.5 890169e094 feat(libc): implement memrchr
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 01:16:53 +02:00
Adrià ecafb64f28 Merge pull request #3083 from MarcZX100/codex/carry-3077-wide-conversions
feat(libc): implement Dinkumware wide conversion exports
2026-10-11 00:01:31 +02:00
DavidandClaude Fable 5.1 51fca3cec3 feat(libc): implement _WStoul, _Iswctype and swscanf_s
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-10 23:44:00 +02:00
DavidandClaude Fable 5.1 63cce467e7 fix(libc): stop strtol at a 0x prefix without hex digits on Windows
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-10 23:40:19 +02:00
Achraf ReyaniandClaude Opus 5.5 909158503d feat(libc): implement atol and atoll
Both parse like strtol and strtoll in base 10. The guest long is 64
bits wide on every host, so atol uses strtoll rather than the host
atol, whose long is 32 bits on Windows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 03:25:22 +09:00
Adrià 7f1b6a0b30 Merge pull request #1507 from ArjenS-LA/fix/libc-wcsrtombs
fix(libc): convert wcsrtombs using guest characters
2026-10-10 03:05:55 +02:00
Claude 8c714f76af fix(libc): stop the wcstol family at a binary prefix on Linux
wcstol, wcstoll, wcstoul and wcstoull parse the ASCII prefix of the
guest's UTF-16 text with std::strtoll and std::strtoull, which glibc 2.38
and later bind to the C23 __isoc23_* functions: wcstol(u"0b101", &end, 0)
returned 5 with the end pointer after the whole string. They now check
StopAtBinaryPrefix_nid_no_patch first, like the narrow functions, and the
end pointer maps back through ParseAsciiPrefix as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 21:26:13 +00:00
Claude b5c9945e1f fix(libc): stop the strtol family at a binary prefix on Linux
C17 has no binary prefix: with base 0 or 2, strtol("0b101", &end, base)
reads the subject "0", returns 0 and leaves end at the 'b'. With glibc
2.38 or later, g++ (which defines _GNU_SOURCE) binds std::strtoll,
strtoull, strtoul, strtoimax and strtoumax to the C23 __isoc23_*
functions, which accept 0b/0B: the Linux exports returned 5 and
consumed the whole string. The Windows UCRT already follows C17, so the
same guest call gave different results on the two hosts.

strtol, strtoul, strtoll, strtoull, _Stoull, strtoimax, strtoumax and
_Stoul now return 0 with the end pointer after the '0' when, after
white space and an optional sign, the text starts with 0b or 0B and a
binary digit, in base 0 or 2. Everything else still goes to the host
function. The scanf family's %i has the same glibc behaviour; it is
recorded in TechnicalDebt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 21:26:13 +00:00
ArjenS-LA 74e1a6f5c4 fix(libc): convert wcsrtombs using guest characters 2026-10-08 11:32:21 -07:00
Fishybeing 5b0d28392c fix(libc): parse and collate guest wide strings as 16-bit units
wcstod, wcstof, wcstold, wcstol, wcstoll, wcstoul, wcstoull, wcscoll and wcsxfrm still forwarded to the host's wchar_t functions, which use 32-bit units on Linux. The wcsto* functions now parse the ASCII prefix of the guest string with the narrow parsers, as the C locale accepts only ASCII white space and digits. wcscoll compares like wcscmp and wcsxfrm copies, as strcoll and strxfrm do in the C locale.
2026-10-08 10:27:00 +02:00