mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-02-28 03:27:58 +08:00
【修复】修复计算中间值溢出问题
rt_tick_from_millisecond 当入参较大时,计算中间值会出现溢出情况,导致转换结果出错
This commit is contained in:
parent
c9d88a8e51
commit
348bd83b08
13
src/clock.c
13
src/clock.c
@ -107,15 +107,20 @@ void rt_tick_increase(void)
|
|||||||
*
|
*
|
||||||
* @return the calculated tick
|
* @return the calculated tick
|
||||||
*/
|
*/
|
||||||
int rt_tick_from_millisecond(rt_int32_t ms)
|
rt_tick_t rt_tick_from_millisecond(rt_int32_t ms)
|
||||||
{
|
{
|
||||||
int tick;
|
rt_tick_t tick;
|
||||||
|
|
||||||
if (ms < 0)
|
if (ms < 0)
|
||||||
|
{
|
||||||
tick = RT_WAITING_FOREVER;
|
tick = RT_WAITING_FOREVER;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
tick = (RT_TICK_PER_SECOND * ms + 999) / 1000;
|
{
|
||||||
|
tick = RT_TICK_PER_SECOND * (ms / 1000);
|
||||||
|
tick += (RT_TICK_PER_SECOND * (ms%1000) + 999) / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
/* return the calculated tick */
|
/* return the calculated tick */
|
||||||
return tick;
|
return tick;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user