aboutsummaryrefslogtreecommitdiff
path: root/world.c
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2023-05-05 09:25:20 +1000
committerquou <quou@disroot.org>2023-05-05 09:25:20 +1000
commit0a083f5a9a747083bbc3a1f0689e76ac5fc3a3b9 (patch)
treeef9a9d883fab808b1d13b8a56b94afb12597bf0f /world.c
parent7fa5b3c842c276859c7d4016b9660e1b16ac30c5 (diff)
Add a check to make sure max_entities doesn't get overflowed.
Diffstat (limited to 'world.c')
-rw-r--r--world.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/world.c b/world.c
index 3b736e6..920484c 100644
--- a/world.c
+++ b/world.c
@@ -1,4 +1,6 @@
#include "world.h"
+#include "platform.h"
+#include "error.h"
void init_world(World* world) {
world->entity_count = 0;
@@ -7,6 +9,16 @@ void init_world(World* world) {
Entity new_entity(World* world) {
Entity e;
+#if DEBUG
+ if (
+ world->entity_count >= max_entities
+ && world->recycle_bin_count == 0
+ ) {
+ platform_err("Too many entities.\n");
+ platform_abort(error_out_of_memory);
+ }
+#endif
+
e =
world->recycle_bin_count > 0 ?
world->recycle_bin[--world->recycle_bin_count] :