From 5d7679de84fc41431b3bc7a137db83f33642779b Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 27 Apr 2016 00:49:52 +0300 Subject: Add checks for wrong timer id. Some times in code it can be 0 and not -1. Now tid is illegal, and tid start counting from 1. --- src/common/timer.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/common/timer.c b/src/common/timer.c index e7a57481a..0b28f6a06 100644 --- a/src/common/timer.c +++ b/src/common/timer.c @@ -51,7 +51,7 @@ struct timer_interface *timer; // timers (array) static struct TimerData* timer_data = NULL; static int timer_data_max = 0; -static int timer_data_num = 0; +static int timer_data_num = 1; // free timers (array) static int* free_timer_list = NULL; @@ -369,6 +369,7 @@ int timer_add_interval(int64 tick, TimerFunc func, int id, intptr_t data, int in /// Retrieves internal timer data const struct TimerData* timer_get(int tid) { + Assert_retr(NULL, tid > 0); return ( tid >= 0 && tid < timer_data_num ) ? &timer_data[tid] : NULL; } @@ -379,7 +380,7 @@ int timer_do_delete(int tid, TimerFunc func) { nullpo_ret(func); - if( tid < 0 || tid >= timer_data_num ) { + if (tid < 1 || tid >= timer_data_num) { ShowError("timer_do_delete error : no such timer [%d](%p(%s))\n", tid, func, search_timer_func_list(func)); Assert_retr(-1, 0); return -1; @@ -406,6 +407,11 @@ int timer_do_delete(int tid, TimerFunc func) /// Adjusts a timer's expiration time. /// Returns the new tick value, or -1 if it fails. int64 timer_addtick(int tid, int64 tick) { + if (tid < 1 || tid >= timer_data_num) { + ShowError("timer_addtick error : no such timer [%d]\n", tid); + Assert_retr(-1, 0); + return -1; + } return timer->settick(tid, timer_data[tid].tick+tick); } -- cgit v1.2.3-60-g2f50