Print an error if too many timers/watches are added

This commit is contained in:
Kovid Goyal 2018-07-11 11:03:52 +05:30
parent 342164ede1
commit d27e7ead49
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

11
glfw/backend_utils.c vendored
View File

@ -7,6 +7,7 @@
#define _GNU_SOURCE #define _GNU_SOURCE
#include "backend_utils.h" #include "backend_utils.h"
#include "internal.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -45,7 +46,10 @@ static id_type watch_counter = 0;
id_type id_type
addWatch(EventLoopData *eld, const char* name, int fd, int events, int enabled, watch_callback_func cb, void *cb_data) { addWatch(EventLoopData *eld, const char* name, int fd, int events, int enabled, watch_callback_func cb, void *cb_data) {
if (eld->watches_count >= sizeof(eld->watches)/sizeof(eld->watches[0])) return 0; if (eld->watches_count >= sizeof(eld->watches)/sizeof(eld->watches[0])) {
_glfwInputError(GLFW_PLATFORM_ERROR, "Too many watches added");
return 0;
}
Watch *w = eld->watches + eld->watches_count++; Watch *w = eld->watches + eld->watches_count++;
w->name = name; w->name = name;
w->fd = fd; w->events = events; w->enabled = enabled; w->fd = fd; w->events = events; w->enabled = enabled;
@ -99,7 +103,10 @@ update_timers(EventLoopData *eld) {
id_type id_type
addTimer(EventLoopData *eld, const char *name, double interval, int enabled, timer_callback_func cb, void *cb_data) { addTimer(EventLoopData *eld, const char *name, double interval, int enabled, timer_callback_func cb, void *cb_data) {
if (eld->timers_count >= sizeof(eld->timers)/sizeof(eld->timers[0])) return 0; if (eld->timers_count >= sizeof(eld->timers)/sizeof(eld->timers[0])) {
_glfwInputError(GLFW_PLATFORM_ERROR, "Too many timers added");
return 0;
}
Timer *t = eld->timers + eld->timers_count++; Timer *t = eld->timers + eld->timers_count++;
t->interval = interval; t->interval = interval;
t->name = name; t->name = name;