Prevent g_sounds[] buffer overflow when attempting to define a sound with an index higher than MAXSOUNDS-1. This reduces the number of sound definitions available by 1 as the last slot is now reserved for the error condition.

git-svn-id: https://svn.eduke32.com/eduke32@7063 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2018-10-10 19:15:22 +00:00
parent 6248cc9cee
commit cc6e458d00

View file

@ -6080,8 +6080,9 @@ repeatcase:
k = *(g_scriptPtr-1);
if (EDUKE32_PREDICT_FALSE((unsigned)k >= MAXSOUNDS-1))
{
initprintf("%s:%d: error: exceeded sound limit of %d.\n",g_scriptFileName,g_lineNumber,MAXSOUNDS);
initprintf("%s:%d: error: sound index exceeds limit of %d.\n",g_scriptFileName,g_lineNumber, MAXSOUNDS-1);
g_errorCnt++;
k = MAXSOUNDS-1;
}
g_scriptPtr--;
i = 0;
@ -6140,7 +6141,7 @@ repeatcase:
if (k > g_highestSoundIdx)
g_highestSoundIdx = k;
if (k >= 0 && k < MAXSOUNDS && g_dynamicSoundMapping && j >= 0 && (labeltype[j] & LABEL_DEFINE))
if (k >= 0 && k < MAXSOUNDS-1 && g_dynamicSoundMapping && j >= 0 && (labeltype[j] & LABEL_DEFINE))
G_ProcessDynamicSoundMapping(label+(j<<6),k);
continue;