From 2f11c7d8026ab4c96ce321f2c714959c52aea062 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Sat, 22 Mar 2014 17:02:21 +0000 Subject: [PATCH] Fix taking ARRAY_SIZE of PlayerSelfObituaries (not PlayerObituaries!) Also add two static assertions checking that the obituary quotes don't go out of the MAXQUOTES bound. BUILD_LUNATIC. git-svn-id: https://svn.eduke32.com/eduke32@4391 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/gamedef.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/polymer/eduke32/source/gamedef.c b/polymer/eduke32/source/gamedef.c index 7b5af6676..529d91948 100644 --- a/polymer/eduke32/source/gamedef.c +++ b/polymer/eduke32/source/gamedef.c @@ -2351,6 +2351,8 @@ LUNATIC_EXTERN void C_DefineProjectile(int32_t j, int32_t what, int32_t val) int32_t C_AllocQuote(int32_t qnum) { + Bassert((unsigned)qnum < MAXQUOTES); + if (ScriptQuotes[qnum] == NULL) { ScriptQuotes[qnum] = (char *)Bcalloc(MAXQUOTELEN,sizeof(uint8_t)); @@ -2448,6 +2450,9 @@ void C_InitQuotes(void) "^02%s^02 bled out", }; + EDUKE32_STATIC_ASSERT(OBITQUOTEINDEX + ARRAY_SIZE(PlayerObituaries)-1 < MAXQUOTES); + EDUKE32_STATIC_ASSERT(SUICIDEQUOTEINDEX + ARRAY_SIZE(PlayerSelfObituaries)-1 < MAXQUOTES); + g_numObituaries = ARRAY_SIZE(PlayerObituaries); for (i=g_numObituaries-1; i>=0; i--) { @@ -2455,7 +2460,7 @@ void C_InitQuotes(void) Bstrcpy(ScriptQuotes[i+OBITQUOTEINDEX],PlayerObituaries[i]); } - g_numSelfObituaries = ARRAY_SIZE(PlayerObituaries); + g_numSelfObituaries = ARRAY_SIZE(PlayerSelfObituaries); for (i=g_numSelfObituaries-1; i>=0; i--) { if (C_AllocQuote(i+SUICIDEQUOTEINDEX))