You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] CWStringTest may not restore the original LC_CTYPE locale #2459
main (the SETLOCALE call and saved pointer already exist in the PR base)
What happened
CWStringTest::EresUnittest_AppendFormatInvalidLocale() saves the pointer returned by SETLOCALE(LC_CTYPE, nullptr), switches the locale to "C", then passes the saved pointer back to restore the locale. In configurations where SETLOCALE maps to libc setlocale, that returned pointer refers to library-managed storage and may be overwritten by the next setlocale call. The restore can therefore leave LC_CTYPE set to "C" instead of restoring the prior locale, affecting later tests in the same process.
This code was present before PR 2453; the PR changes the standalone test to call setlocale directly but does not introduce the saved-pointer pattern.
What should happen instead
Copy the locale name before changing it, then restore using the copy.
How to reproduce
Run the equivalent sequence with a non-CLC_CTYPE locale (for example, LC_ALL=en_US.UTF-8): save setlocale(LC_CTYPE, nullptr), call setlocale(LC_CTYPE, "C"), then call setlocale(LC_CTYPE, saved). On this machine, the saved pointer's contents changed to "C" after the second call, and the restore left the current locale at "C".
The GPORCA test itself is excluded on Darwin; the test suite runs this case on Linux, where the same setlocale pointer lifetime should be verified.
Operating System
Reproduced with the platform libc on macOS 14.6, arm64. The affected GPORCA test is enabled on non-Darwin platforms.
Code location (the form already present in the PR base): CWStringTest.cpp, lines 181–192. This saves the pointer returned by SETLOCALE(LC_CTYPE, nullptr), switches the locale to "C", and then tries to restore the locale using the saved pointer.
Activity
tuhaihe commentedon Dec 1, 2026
Code location (the form already present in the PR base): CWStringTest.cpp, lines 181–192. This saves the pointer returned by
SETLOCALE(LC_CTYPE, nullptr), switches the locale to"C", and then tries to restore the locale using the saved pointer.