summaryrefslogtreecommitdiff
path: root/apps/plugins/mikmod/load_mtm.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/mikmod/load_mtm.c')
-rw-r--r--apps/plugins/mikmod/load_mtm.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/apps/plugins/mikmod/load_mtm.c b/apps/plugins/mikmod/load_mtm.c
index 6c9fb30846..5620575a10 100644
--- a/apps/plugins/mikmod/load_mtm.c
+++ b/apps/plugins/mikmod/load_mtm.c
@@ -6,12 +6,12 @@
6 it under the terms of the GNU Library General Public License as 6 it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of 7 published by the Free Software Foundation; either version 2 of
8 the License, or (at your option) any later version. 8 the License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Library General Public License for more details. 13 GNU Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public 15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free Software 16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
@@ -20,7 +20,7 @@
20 20
21/*============================================================================== 21/*==============================================================================
22 22
23 $Id: load_mtm.c,v 1.3 2005/04/07 19:57:38 realtech Exp $ 23 $Id$
24 24
25 MTM module loader 25 MTM module loader
26 26
@@ -108,6 +108,8 @@ static void MTM_Cleanup(void)
108{ 108{
109 MikMod_free(mtmtrk); 109 MikMod_free(mtmtrk);
110 MikMod_free(mh); 110 MikMod_free(mh);
111 mtmtrk=NULL;
112 mh=NULL;
111} 113}
112 114
113static UBYTE* MTM_Convert(void) 115static UBYTE* MTM_Convert(void)
@@ -145,7 +147,7 @@ static int MTM_Load(int curious)
145 int t,u; 147 int t,u;
146 MTMSAMPLE s; 148 MTMSAMPLE s;
147 SAMPLE *q; 149 SAMPLE *q;
148 (void)curious; 150 (void)curious;
149 151
150 /* try to read module header */ 152 /* try to read module header */
151 _mm_read_UBYTES(mh->id,3,modreader); 153 _mm_read_UBYTES(mh->id,3,modreader);
@@ -169,7 +171,7 @@ static int MTM_Load(int curious)
169 /* set module variables */ 171 /* set module variables */
170 of.initspeed = 6; 172 of.initspeed = 6;
171 of.inittempo = 125; 173 of.inittempo = 125;
172 of.modtype = StrDup(MTM_Version); 174 of.modtype = MikMod_strdup(MTM_Version);
173 of.numchn = mh->numchannels; 175 of.numchn = mh->numchannels;
174 of.numtrk = mh->numtracks+1; /* get number of channels */ 176 of.numtrk = mh->numtracks+1; /* get number of channels */
175 of.songname = DupStr(mh->songname,20,1); /* make a cstr of songname */ 177 of.songname = DupStr(mh->songname,20,1); /* make a cstr of songname */
@@ -193,7 +195,7 @@ static int MTM_Load(int curious)
193 s.attribute =_mm_read_UBYTE(modreader); 195 s.attribute =_mm_read_UBYTE(modreader);
194 196
195 if(_mm_eof(modreader)) { 197 if(_mm_eof(modreader)) {
196 _mm_errno = MMERR_LOADING_SAMPLEINFO; 198 _mm_errno = MMERR_LOADING_SAMPLEINFO;
197 return 0; 199 return 0;
198 } 200 }
199 201
@@ -218,9 +220,15 @@ static int MTM_Load(int curious)
218 } 220 }
219 221
220 if(!AllocPositions(of.numpos)) return 0; 222 if(!AllocPositions(of.numpos)) return 0;
221 for(t=0;t<of.numpos;t++) 223 for(t=0;t<of.numpos;t++) {
222 of.positions[t]=_mm_read_UBYTE(modreader); 224 of.positions[t]=_mm_read_UBYTE(modreader);
223 for(;t<128;t++) (void)_mm_read_UBYTE(modreader); 225 if (of.positions[t]>of.numpat) { /* SANITIY CHECK */
226 /* fprintf(stderr,"positions[%d]=%d > numpat=%d\n",t,of.positions[t],of.numpat);*/
227 _mm_errno = MMERR_LOADING_HEADER;
228 return 0;
229 }
230 }
231 for(;t<128;t++) _mm_skip_BYTE(modreader);
224 if(_mm_eof(modreader)) { 232 if(_mm_eof(modreader)) {
225 _mm_errno = MMERR_LOADING_HEADER; 233 _mm_errno = MMERR_LOADING_HEADER;
226 return 0; 234 return 0;
@@ -231,12 +239,12 @@ static int MTM_Load(int curious)
231 239
232 of.tracks[0]=MTM_Convert(); /* track 0 is empty */ 240 of.tracks[0]=MTM_Convert(); /* track 0 is empty */
233 for(t=1;t<of.numtrk;t++) { 241 for(t=1;t<of.numtrk;t++) {
234 int s; 242 int s_idx;
235 243
236 for(s=0;s<64;s++) { 244 for(s_idx=0;s_idx<64;s_idx++) {
237 mtmtrk[s].a=_mm_read_UBYTE(modreader); 245 mtmtrk[s_idx].a=_mm_read_UBYTE(modreader);
238 mtmtrk[s].b=_mm_read_UBYTE(modreader); 246 mtmtrk[s_idx].b=_mm_read_UBYTE(modreader);
239 mtmtrk[s].c=_mm_read_UBYTE(modreader); 247 mtmtrk[s_idx].c=_mm_read_UBYTE(modreader);
240 } 248 }
241 249
242 if(_mm_eof(modreader)) { 250 if(_mm_eof(modreader)) {