Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 93f32ea

Browse files
authored
modus/modutime.c: avoid the overrun condition when using results from ticks_xx() in ticks_diff()
Make ticks_add consistent to ticks_diff And also still avoid the overrun condition when using results from ticks_xx() in ticks_diff() and ticks_add()
1 parent 6517888 commit 93f32ea

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

esp32/mods/modutime.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,14 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_ticks_cpu_obj, time_ticks_cpu);
172172
STATIC mp_obj_t time_ticks_diff(mp_obj_t start_in, mp_obj_t end_in) {
173173
int32_t start = mp_obj_get_int_truncated(start_in);
174174
int32_t end = mp_obj_get_int_truncated(end_in);
175-
return mp_obj_new_int((end - start));
175+
return mp_obj_new_int(end - start);
176176
}
177177
STATIC MP_DEFINE_CONST_FUN_OBJ_2(time_ticks_diff_obj, time_ticks_diff);
178178

179179
STATIC mp_obj_t time_ticks_add(mp_obj_t start_in, mp_obj_t delta_in) {
180-
uint32_t start = mp_obj_get_int_truncated(start_in);
181-
uint32_t delta = mp_obj_get_int_truncated(delta_in);
182-
return mp_obj_new_int_from_uint((start + delta));
180+
int32_t start = mp_obj_get_int_truncated(start_in);
181+
int32_t delta = mp_obj_get_int_truncated(delta_in);
182+
return mp_obj_new_int(start + delta);
183183
}
184184
STATIC MP_DEFINE_CONST_FUN_OBJ_2(time_ticks_add_obj, time_ticks_add);
185185

0 commit comments

Comments
 (0)