mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-07 20:08:13 +00:00
Added more error checking for SDL timer functions
This commit is contained in:
@@ -279,6 +279,11 @@ static SDL_TimerID SDL_CreateTimer(Uint64 interval, SDL_TimerCallback callback_m
|
||||
SDL_Timer *timer;
|
||||
SDL_TimerMap *entry;
|
||||
|
||||
if (!callback_ms && !callback_ns) {
|
||||
SDL_InvalidParamError("callback");
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_LockSpinlock(&data->lock);
|
||||
if (!SDL_AtomicGet(&data->active)) {
|
||||
if (SDL_InitTimers() < 0) {
|
||||
@@ -350,6 +355,10 @@ int SDL_RemoveTimer(SDL_TimerID id)
|
||||
SDL_TimerMap *prev, *entry;
|
||||
SDL_bool canceled = SDL_FALSE;
|
||||
|
||||
if (!id) {
|
||||
return SDL_InvalidParamError("id");
|
||||
}
|
||||
|
||||
/* Find the timer */
|
||||
SDL_LockMutex(data->timermap_lock);
|
||||
prev = NULL;
|
||||
@@ -439,6 +448,11 @@ static SDL_TimerID SDL_CreateTimer(Uint64 interval, SDL_TimerCallback callback_m
|
||||
SDL_TimerData *data = &SDL_timer_data;
|
||||
SDL_TimerMap *entry;
|
||||
|
||||
if (!callback_ms && !callback_ns) {
|
||||
SDL_InvalidParamError("callback");
|
||||
return 0;
|
||||
}
|
||||
|
||||
entry = (SDL_TimerMap *)SDL_malloc(sizeof(*entry));
|
||||
if (!entry) {
|
||||
return 0;
|
||||
@@ -474,6 +488,10 @@ int SDL_RemoveTimer(SDL_TimerID id)
|
||||
SDL_TimerData *data = &SDL_timer_data;
|
||||
SDL_TimerMap *prev, *entry;
|
||||
|
||||
if (!id) {
|
||||
return SDL_InvalidParamError("id");
|
||||
}
|
||||
|
||||
/* Find the timer */
|
||||
prev = NULL;
|
||||
for (entry = data->timermap; entry; prev = entry, entry = entry->next) {
|
||||
|
Reference in New Issue
Block a user