Skip to content

Commit 4ab00d7

Browse files
committed
mp_hal_delay_ms: avoid overflow when scaling ticks
This patch casts the delay argument to mp_hal_delay_ms() from mp_uint_t to uint64_t when scaling from milliseconds to ticks to avoid 32-bit integer overflow when time.sleep() is called with a duration of greater than 70 minutes. Signed-off-by: Trammell Hudson <[email protected]>
1 parent f5ef255 commit 4ab00d7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

supervisor/shared/tick.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ void PLACE_IN_ITCM(supervisor_run_background_tasks_if_tick)() {
127127
background_callback_run_all();
128128
}
129129

130-
void mp_hal_delay_ms(mp_uint_t delay) {
130+
void mp_hal_delay_ms(mp_uint_t delay_ms) {
131131
uint64_t start_tick = port_get_raw_ticks(NULL);
132132
// Adjust the delay to ticks vs ms.
133-
delay = delay * 1024 / 1000;
134-
uint64_t end_tick = start_tick + delay;
135-
int64_t remaining = delay;
133+
uint64_t delay_ticks = (delay_ms * (uint64_t)1024) / 1000;
134+
uint64_t end_tick = start_tick + delay_ticks;
135+
int64_t remaining = delay_ticks;
136136

137137
// Loop until we've waited long enough or we've been CTRL-Ced by autoreload
138138
// or the user.

0 commit comments

Comments
 (0)