# HG changeset patch # User Matti Hamalainen # Date 1509379958 -7200 # Node ID b47109fce3758bf28c0f9842cdf4504740eb38b8 # Parent aaed8fa9a11fd708869721bb8341c92ac5aedd79 Make JSSExtInstrument.instConvSamples dynamically allocated and add check for XM_MaxInstSamples in XM loader. diff -r aaed8fa9a11f -r b47109fce375 minijss/jloadxm.c --- a/minijss/jloadxm.c Mon Oct 30 18:01:25 2017 +0200 +++ b/minijss/jloadxm.c Mon Oct 30 18:12:38 2017 +0200 @@ -773,6 +773,13 @@ return DMERR_OK; } + if (xmI1.nsamples > XM_MaxInstSamples) + { + JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, + "Extended instrument #%d has invalid number of samples %d.\n", + neinst, xmI1.nsamples); + } + // Allocate instrument JSSDEBUG("Allocating extended instrument #%d [%d]\n", neinst, module->nextInstruments); @@ -860,11 +867,18 @@ einst->nsamples = xmI1.nsamples; // Initialize the SNumForNotes conversion table + if ((einst->instConvTable = dmCalloc(XM_MaxInstruments + 1, sizeof(int))) == NULL) + { + JSSERROR(DMERR_MALLOC, DMERR_MALLOC, + "Could not allocate memory for instConvTable of instrument #%d.\n", + neinst); + } + for (i = 0; i < XM_MaxInstruments; i++) einst->instConvTable[i] = jsetNotSet; // Read sample headers - for (nsample = 0; nsample < xmI1.nsamples; nsample++) + for (nsample = 0; nsample < einst->nsamples; nsample++) { if ((ret = jssXMLoadSampleInstrument(inFile, module, einst, neinst, nsample)) != DMERR_OK) return ret; diff -r aaed8fa9a11f -r b47109fce375 minijss/jssmod.c --- a/minijss/jssmod.c Mon Oct 30 18:01:25 2017 +0200 +++ b/minijss/jssmod.c Mon Oct 30 18:12:38 2017 +0200 @@ -430,10 +430,7 @@ // Initialize the requisite fields for (i = 0; i < jsetNNotes; i++) - { inst->sNumForNotes[i] = jsetNotSet; - inst->instConvTable[i] = jsetNotSet; - } return inst; } @@ -446,6 +443,7 @@ #ifndef JSS_LIGHT dmFree(inst->desc); #endif + dmFree(inst->instConvTable); dmFree(inst); } } diff -r aaed8fa9a11f -r b47109fce375 minijss/jssmod.h --- a/minijss/jssmod.h Mon Oct 30 18:01:25 2017 +0200 +++ b/minijss/jssmod.h Mon Oct 30 18:12:38 2017 +0200 @@ -119,7 +119,8 @@ #endif int nsamples, sNumForNotes[jsetNNotes], - instConvTable[jsetNNotes]; + *instConvTable; + JSSEnvelope volumeEnv, panningEnv; int vibratoType, vibratoSweep,