Skip to content

[Bug] CWStringTest may not restore the original LC_CTYPE locale #2459

Backlog

Description

@tuhaihe

Apache Cloudberry version

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-C LC_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.

Anything else

  • Yes, I am willing to submit a PR!

Activity

  1. added
    type: Bug
    on Dec 1, 2026
  2. tuhaihe commented on Dec 1, 2026

    @tuhaihe
    MemberAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions