[Bug] CWStringTest may not restore the original LC_CTYPE locale

未关闭 适合新手
#2,459 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
c
领域
testing

调研方向

在 GPORCA 测试代码中找到 CWStringTest::EresUnittest_AppendFormatInvalidLocale(),检查它如何在切换到 "C" 前后保存和恢复 LC_CTYPE。在更改 locale 名称前先复制它,然后从该副本恢复。请在 Linux 上运行受影响的测试,并确认它为后续测试恢复了原始 locale。

由索引模型根据 Issue 内容生成。

描述

type: Bug
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!
主要语言
C
星标
1.5k
派生
280
平均合并
5 天 35 分钟
30 天内合并 PR
128

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/cloudberry 的其他 Issue

查看 apache/cloudberry 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。