Mercurial > hg > dmlib
comparison minijss/jloadxm.c @ 1402:b47109fce375
Make JSSExtInstrument.instConvSamples dynamically allocated and add check
for XM_MaxInstSamples in XM loader.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 30 Oct 2017 18:12:38 +0200 |
parents | 496d04ab495f |
children | e0f9200b94ad |
comparison
equal
deleted
inserted
replaced
1401:aaed8fa9a11f | 1402:b47109fce375 |
---|---|
771 dmfseek(inFile, remainder, SEEK_CUR); | 771 dmfseek(inFile, remainder, SEEK_CUR); |
772 } | 772 } |
773 return DMERR_OK; | 773 return DMERR_OK; |
774 } | 774 } |
775 | 775 |
776 if (xmI1.nsamples > XM_MaxInstSamples) | |
777 { | |
778 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
779 "Extended instrument #%d has invalid number of samples %d.\n", | |
780 neinst, xmI1.nsamples); | |
781 } | |
782 | |
776 // Allocate instrument | 783 // Allocate instrument |
777 JSSDEBUG("Allocating extended instrument #%d [%d]\n", | 784 JSSDEBUG("Allocating extended instrument #%d [%d]\n", |
778 neinst, module->nextInstruments); | 785 neinst, module->nextInstruments); |
779 | 786 |
780 if ((einst = jssAllocateExtInstrument()) == NULL) | 787 if ((einst = jssAllocateExtInstrument()) == NULL) |
858 einst->vibratoRate = xmI2.vibratoRate; | 865 einst->vibratoRate = xmI2.vibratoRate; |
859 einst->fadeOut = xmI2.fadeOut; | 866 einst->fadeOut = xmI2.fadeOut; |
860 einst->nsamples = xmI1.nsamples; | 867 einst->nsamples = xmI1.nsamples; |
861 | 868 |
862 // Initialize the SNumForNotes conversion table | 869 // Initialize the SNumForNotes conversion table |
870 if ((einst->instConvTable = dmCalloc(XM_MaxInstruments + 1, sizeof(int))) == NULL) | |
871 { | |
872 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, | |
873 "Could not allocate memory for instConvTable of instrument #%d.\n", | |
874 neinst); | |
875 } | |
876 | |
863 for (i = 0; i < XM_MaxInstruments; i++) | 877 for (i = 0; i < XM_MaxInstruments; i++) |
864 einst->instConvTable[i] = jsetNotSet; | 878 einst->instConvTable[i] = jsetNotSet; |
865 | 879 |
866 // Read sample headers | 880 // Read sample headers |
867 for (nsample = 0; nsample < xmI1.nsamples; nsample++) | 881 for (nsample = 0; nsample < einst->nsamples; nsample++) |
868 { | 882 { |
869 if ((ret = jssXMLoadSampleInstrument(inFile, module, einst, neinst, nsample)) != DMERR_OK) | 883 if ((ret = jssXMLoadSampleInstrument(inFile, module, einst, neinst, nsample)) != DMERR_OK) |
870 return ret; | 884 return ret; |
871 } | 885 } |
872 | 886 |