summaryrefslogtreecommitdiffstats
path: root/apps/plugins/mikmod/load_gdm.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/mikmod/load_gdm.c')
-rw-r--r--apps/plugins/mikmod/load_gdm.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/apps/plugins/mikmod/load_gdm.c b/apps/plugins/mikmod/load_gdm.c
index 694d534236..5f06f9c70b 100644
--- a/apps/plugins/mikmod/load_gdm.c
+++ b/apps/plugins/mikmod/load_gdm.c
@@ -20,7 +20,7 @@
/*==============================================================================
- $Id: load_gdm.c,v 1.3 2005/04/07 19:57:38 realtech Exp $
+ $Id$
General DigiMusic (GDM) module loader
@@ -114,7 +114,7 @@ typedef struct GDMSAMPLE {
static GDMHEADER *mh=NULL; /* pointer to GDM header */
static GDMNOTE *gdmbuf=NULL; /* pointer to a complete GDM pattern */
-CHAR GDM_Version[]="General DigiMusic 1.xx";
+static CHAR GDM_Version[]="General DigiMusic 1.xx";
static int GDM_Test(void)
{
@@ -146,36 +146,45 @@ static void GDM_Cleanup(void)
{
MikMod_free(mh);
MikMod_free(gdmbuf);
+ mh=NULL;
+ gdmbuf=NULL;
}
static int GDM_ReadPattern(void)
{
- int pos,flag,ch,i,maxch;
+ int pos,flag,ch,i;
GDMNOTE n;
- UWORD length,x=0;
+ SLONG length,x=0;
/* get pattern length */
- length=_mm_read_I_UWORD(modreader)-2;
+ length=(SLONG)_mm_read_I_UWORD(modreader);
+ length-=2;
/* clear pattern data */
memset(gdmbuf,255,32*64*sizeof(GDMNOTE));
pos=0;
- maxch=0;
while (x<length) {
memset(&n,255,sizeof(GDMNOTE));
flag=_mm_read_UBYTE(modreader);
x++;
- if (_mm_eof(modreader)) {
- _mm_errno=MMERR_LOADING_PATTERN;
+ if (_mm_eof(modreader))
return 0;
- }
ch=flag&31;
- if (ch>maxch) maxch=ch;
+ if (ch > of.numchn)
+ return 0;
+
if (!flag) {
pos++;
+ if (x==length) {
+ if (pos > 64)
+ return 0;
+ } else {
+ if (pos >= 64)
+ return 0;
+ }
continue;
}
if (flag&0x60) {
@@ -343,7 +352,7 @@ static int GDM_Load(int curious)
SAMPLE *q;
GDMSAMPLE s;
ULONG position;
- (void)curious;
+ (void)curious;
/* read header */
_mm_read_string(mh->id1,4,modreader);
@@ -390,7 +399,7 @@ static int GDM_Load(int curious)
}
/* now we fill */
- of.modtype=StrDup(GDM_Version);
+ of.modtype=MikMod_strdup(GDM_Version);
of.modtype[18]=mh->majorver+'0';
of.modtype[20]=mh->minorver/10+'0';
of.modtype[21]=mh->minorver%10+'0';