aboutsummaryrefslogtreecommitdiffstats
path: root/src/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common.c')
-rw-r--r--src/common.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/common.c b/src/common.c
index 6f1e017..46b2f3d 100644
--- a/src/common.c
+++ b/src/common.c
@@ -146,12 +146,20 @@ puglNewView(PuglWorld* const world)
puglSetDefaultHints(view->hints);
- // Add to world view list
- ++world->numViews;
- world->views =
- (PuglView**)realloc(world->views, world->numViews * sizeof(PuglView*));
+ // Enlarge world view list
+ const size_t newNumViews = world->numViews + 1U;
+ PuglView** const views =
+ (PuglView**)realloc(world->views, newNumViews * sizeof(PuglView*));
+
+ if (!views) {
+ free(view);
+ return NULL;
+ }
- world->views[world->numViews - 1] = view;
+ // Add to world view list
+ world->views = views;
+ world->views[world->numViews] = view;
+ world->numViews = newNumViews;
return view;
}