summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-04-27 00:49:52 +0300
committerAndrei Karas <akaras@inbox.ru>2016-04-27 01:24:38 +0300
commit5d7679de84fc41431b3bc7a137db83f33642779b (patch)
treefcf2538c2b6c851562ff132a8142764335efc662
parent9b7f03b129503362c6349e0c0f7f42637df32ab5 (diff)
downloadhercules-5d7679de84fc41431b3bc7a137db83f33642779b.tar.gz
hercules-5d7679de84fc41431b3bc7a137db83f33642779b.tar.bz2
hercules-5d7679de84fc41431b3bc7a137db83f33642779b.tar.xz
hercules-5d7679de84fc41431b3bc7a137db83f33642779b.zip
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.
-rw-r--r--src/common/timer.c10
1 files 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);
}