Skip to content

Commit 348bd83

Browse files
authored
【修复】修复计算中间值溢出问题
rt_tick_from_millisecond 当入参较大时,计算中间值会出现溢出情况,导致转换结果出错
1 parent c9d88a8 commit 348bd83

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/clock.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,20 @@ void rt_tick_increase(void)
107107
*
108108
* @return the calculated tick
109109
*/
110-
int rt_tick_from_millisecond(rt_int32_t ms)
110+
rt_tick_t rt_tick_from_millisecond(rt_int32_t ms)
111111
{
112-
int tick;
112+
rt_tick_t tick;
113113

114114
if (ms < 0)
115+
{
115116
tick = RT_WAITING_FOREVER;
117+
}
116118
else
117-
tick = (RT_TICK_PER_SECOND * ms + 999) / 1000;
118-
119+
{
120+
tick = RT_TICK_PER_SECOND * (ms / 1000);
121+
tick += (RT_TICK_PER_SECOND * (ms%1000) + 999) / 1000;
122+
}
123+
119124
/* return the calculated tick */
120125
return tick;
121126
}

0 commit comments

Comments
 (0)