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
#ifdef RT_USING_RTC
- if (tv != RT_NULL && (long)tv->tv_usec >= 0 && (long)tv->tv_sec >= 0)+ /*+ * Check the fields by their own type. Casting tv_sec to long narrows it on+ * ILP32 targets where time_t is 64 bit (time64/long32): every timestamp+ * above INT32_MAX turned negative and was rejected with EINVAL, even though+ * it is a perfectly valid value for time_t.+ */+ if (tv != RT_NULL && tv->tv_usec >= 0 && tv->tv_sec >= 0)
{
Activity
github-actions commentedon Oct 23, 2026
如需认领并处理此 Issue,请评论
/claim。To claim and work on this issue, comment
/claim.Yunlk commentedon Oct 24, 2026
/claim
github-actions commentedon Oct 24, 2026
@Yunlk has claimed this issue.
Yunlk commentedon Oct 24, 2026
在 QEMU 上实测复现了,也验证了改法。边界和你说的完全一致。
环境
bsp/qemu-vexpress-a9(32 位 ARM,RT_USING_RTC=y,板上有 rtc 设备)1c801efasizeof(time_t)=8、sizeof(long)=4—— 正是 time64/long32复现(未修复)
逐点扫了一遍边界:
首个被拒值正好是
2147483648,与 issue 里写的区间一致;INT32_MAX及以下不受影响。改法
去掉强转,按字段自身类型校验:
改完同一份固件重跑,五个点全部
ret=0,INT32_MAX以下行为未变。两点补充
tv_usec的强转也一并去掉了,但它在 ILP32 上本来就没问题(suseconds_t32 位);保留只是为了和tv_sec写法统一。如果你希望改动更小,只动tv_sec也可以。顺带发现但未改动:这里只校验了
tv_usec >= 0,没有校验 POSIX 要求的< 1000000。传tv_usec = 5000000目前会被放行并送进 RTC 驱动。这属于另一处校验缺失,是否一并收紧由维护者判断,我没有把它混进这次的改动。关于 utest
这个用例要能跑,前提是系统里有
rtc设备(_control_rtc()走rt_device_find("rtc"),找不到会直接返回-RT_ENOSYS,和强转问题是两条不同的失败路径)。CI 里 qemu-vexpress-a9 有 rtc,所以理论上可以加;但需要确认其他跑 utest 的 BSP 是否都有 rtc 设备,否则用例会因为找不到设备而误失败。如果需要,我可以把补丁提成 PR,并附一条在
-DRT_USING_RTC下条件编译的 utest(断言INT32_MAX + 1与2208988800两个值能通过)。