Skip to content

Commit dfc4eff

Browse files
author
Pierluigi Petrelli
committed
Fixing a crash
1 parent 977daf1 commit dfc4eff

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/timer.h

+6-8
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Timer {
6161
{
6262
struct task *_task;
6363
_task = add_task(time_func(), delay, h, opaque);
64-
return _task->id;
64+
return (_task) ? _task->id : 0;
6565
}
6666

6767
/* Calls handler with opaque as argument at time */
@@ -71,7 +71,7 @@ class Timer {
7171
struct task *_task;
7272
const unsigned long now = time_func();
7373
_task = add_task(now, time - now, h, opaque);
74-
return _task->id;
74+
return (_task) ? _task->id : 0;
7575
}
7676

7777
/* Calls handler with opaque as argument every interval units of time */
@@ -80,7 +80,7 @@ class Timer {
8080
{
8181
struct task *_task;
8282
_task = add_task(time_func(), interval, h, opaque, interval);
83-
return _task->id;
83+
return (_task) ? _task->id : 0;
8484
}
8585

8686
/* Cancel a task by id*/
@@ -175,11 +175,9 @@ class Timer {
175175
{
176176
struct task * const slot = next_task_slot();
177177

178-
if (!slot)
179-
slot->id = 0;
180-
else
181-
slot->id = next_task_id();//random(2147483646);
182-
178+
if (!slot) return NULL;
179+
180+
slot->id = next_task_id();
183181
slot->handler = h;
184182
slot->opaque = opaque;
185183
slot->start = start;

0 commit comments

Comments
 (0)