From 9cf7da43667425bd889211a2d5a69659a10fe9c7 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Sun, 29 Mar 2015 02:40:15 +0000 Subject: [PATCH] Avoid triggering undefined behavior in the allocator when loading or saving ProjectileData[]. git-svn-id: https://svn.eduke32.com/eduke32@5111 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/savegame.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/polymer/eduke32/source/savegame.c b/polymer/eduke32/source/savegame.c index 7fb9e2929..bec58a714 100644 --- a/polymer/eduke32/source/savegame.c +++ b/polymer/eduke32/source/savegame.c @@ -1724,7 +1724,8 @@ static void sv_quoteload() static void sv_preprojectilesave() { - ProjectileData = (projectile_t *) Xrealloc(ProjectileData, sizeof(projectile_t) * g_numProjectiles); + if (ProjectileData != NULL || g_numProjectiles > 0) + ProjectileData = (projectile_t *) Xrealloc(ProjectileData, sizeof(projectile_t) * g_numProjectiles); #ifdef DEBUGGINGAIDS int onumprojectiles = g_numProjectiles; #endif @@ -1752,7 +1753,8 @@ static void sv_postprojectilesave() static void sv_preprojectileload() { - ProjectileData = (projectile_t *) Xrealloc(ProjectileData, sizeof(projectile_t) * g_numProjectiles); + if (ProjectileData != NULL || g_numProjectiles > 0) + ProjectileData = (projectile_t *) Xrealloc(ProjectileData, sizeof(projectile_t) * g_numProjectiles); } static void sv_postprojectileload()