[fix][kernel] fix timegm month overflow calculation - #11720
Conversation
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
📌 Code Review Assignment🏷️ Tag: componentsReviewers: @Maihuanyi Changed Files (Click to expand)
🏷️ Tag: components_libcReviewers: @GorrayLi @mysterywolf Changed Files (Click to expand)
🏷️ Tag: kernelReviewers: @GorrayLi @ReviewSun @hamburger-os @lianux-mm @wdfk-prog @xu18838022837 Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-08-19 14:15 CST)
📝 Review Instructions
|
45041bb to
9ac763e
Compare
|
80b8771 to
00764ae
Compare
When days exceed the number of days in the current month, the original code incorrectly used __spm[t->tm_mon] as the monthly offset, causing wrong date results after crossing month boundaries (e.g. adding 420 days to 2026/08/05 gave 2027/03/01 instead of 2027/09/29). Fix the overflow logic to use (__spm[mon+1] - __spm[mon]) with proper leap-year adjustment for February. Close RT-Thread#11686 Signed-off-by: Hui Su <3164683437@qq.com>
00764ae to
60cc901
Compare
When days exceed the number of days in the current month, the original code incorrectly used __spm[t->tm_mon] as the monthly offset, causing wrong date results after crossing month boundaries (e.g. adding 420 days to 2026/08/05 gave 2027/03/01 instead of 2027/09/29).
Fix the overflow logic to use (__spm[mon+1] - __spm[mon]) with proper leap-year adjustment for February.
Close #11686
拉取/合并请求描述:(PR description)
为什么提交这份PR (why to submit this PR)
修复 timegm() 函数在 tm_mday 跨月时的计算错误(Issue #11686)。例如 2026/08/05 + 420天 预期 2027/09/29,实际返回 2027/03/01。
你的解决方案是什么 (what is your solution)
原代码 while (t->tm_mday > __spm[1 + t->tm_mon]) 直接用 __spm 的累积天数做比较,跨月减法逻辑错误。修复为使用 __spm[mon+1] - __spm[mon] 计算当月实际天数,并正确处理闰年二月。
同时新增 src/utest/time_tc.c 测试用例,覆盖跨月边界、闰年二月、大天数偏移三个场景。
请提供验证的bsp和config (provide the config and bsp)
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up