shithub: dumb

Download patch

ref: 9b377f8d7f76159d7f227c727aeae7e16fd1db7b
parent: e12facc69845ef4f16bc70f755dc7cb898cede41
author: Chris Moeller <kode54@gmail.com>
date: Sat Jun 15 15:48:23 EDT 2013

Cleaned up several warnings, including a buffer
overflow in the DSMF reader

--- a/dumb/include/internal/it.h
+++ b/dumb/include/internal/it.h
@@ -210,7 +210,7 @@
 struct IT_SAMPLE
 {
 	unsigned char name[35];
-	unsigned char filename[14];
+	unsigned char filename[15];
 	unsigned char flags;
 	unsigned char global_volume;
 	unsigned char default_volume;
--- a/dumb/src/it/readokt.c
+++ b/dumb/src/it/readokt.c
@@ -486,7 +486,7 @@
 
 	/* And finally, the sample data */
 	k = get_chunk_count(mod, DUMB_ID('S','B','O','D'));
-	for (i = 0, j = 0; i < sigdata->n_samples, j < k; i++) {
+	for (i = 0, j = 0; i < sigdata->n_samples && j < k; i++) {
 		if (sigdata->sample[i].flags & IT_SAMPLE_EXISTS) {
 			chunk = get_chunk_by_type(mod, DUMB_ID('S','B','O','D'), j);
 			if (it_okt_read_sample_data(&sigdata->sample[i], (const char *)chunk->data, chunk->size)) {
@@ -503,7 +503,7 @@
 
 	chunk = get_chunk_by_type(mod, DUMB_ID('C','M','O','D'), 0);
 
-	for (i = 0, j = 0; i < n_channels, j < 4; j++) {
+	for (i = 0, j = 0; i < n_channels && j < 4; j++) {
 		k = (chunk->data[j * 2] << 8) | chunk->data[j * 2 + 1];
 		l = (j == 1 || j == 2) ? 48 : 16;
 		if (k == 0) {
--- a/dumb/src/it/readpsm.c
+++ b/dumb/src/it/readpsm.c
@@ -81,7 +81,7 @@
 		panpos = data[0x43];
 		defvol = data[0x44];
 		samplerate = data[0x49] | (data[0x4A] << 8) | (data[0x4B] << 16) | (data[0x4C] << 24);
-	} else if (version == PSMV_NEW) {
+	} else /*if (version == PSMV_NEW)*/ {
 		memcpy(sample->name, data + 0x11, 34);
 		sample->name[34] = 0;
 
@@ -154,7 +154,7 @@
 		if (len < 10) return -1;
 		data += 8;
 		len -= 8;
-	} else if (version == PSMV_NEW) {
+	} else /*if (version == PSMV_NEW)*/ {
 		if (len < 14) return -1;
 		data += 12;
 		len -= 12;
@@ -291,7 +291,7 @@
 				if (version == PSMV_OLD) {
 					if ((data[pos] < 0x80)) entry->note = (data[pos]>>4)*12+(data[pos]&0x0f)+12;
 					else entry->mask &= ~IT_ENTRY_NOTE;
-				} else if (version == PSMV_NEW) {
+				} else /*if (version == PSMV_NEW)*/ {
 					if ((data[pos]) && (data[pos] < 84)) entry->note = data[pos] + 35;
 					else entry->mask &= ~IT_ENTRY_NOTE;
 				}
@@ -315,25 +315,25 @@
 					case 1:
 						entry->effect = IT_VOLUME_SLIDE;
 						if (version == PSMV_OLD) entry->effectvalue = ((length&0x1e)<<3) | 0xF;
-						else if (version == PSMV_NEW) entry->effectvalue = (length<<4) | 0xF;
+						else /*if (version == PSMV_NEW)*/ entry->effectvalue = (length<<4) | 0xF;
 						break;
 
 					case 2:
 						entry->effect = IT_VOLUME_SLIDE;
 						if (version == PSMV_OLD) entry->effectvalue = (length << 3) & 0xF0;
-						else if (version == PSMV_NEW) entry->effectvalue = (length << 4) & 0xF0;
+						else /*if (version == PSMV_NEW)*/ entry->effectvalue = (length << 4) & 0xF0;
 						break;
 
 					case 3:
 						entry->effect = IT_VOLUME_SLIDE;
 						if (version == PSMV_OLD) entry->effectvalue = (length >> 1) | 0xF0;
-						else if (version == PSMV_NEW) entry->effectvalue = length | 0xF0;
+						else /*if (version == PSMV_NEW)*/ entry->effectvalue = length | 0xF0;
 						break;
 
 					case 4:
 						entry->effect = IT_VOLUME_SLIDE;
 						if (version == PSMV_OLD) entry->effectvalue = (length >> 1) & 0xF;
-						else if (version == PSMV_NEW) entry->effectvalue = length & 0xF;
+						else /*if (version == PSMV_NEW)*/ entry->effectvalue = length & 0xF;
 						break;
 
 					case 12:
@@ -341,7 +341,7 @@
 						if (version == PSMV_OLD) {
 							if (length < 4) entry->effectvalue = length | 0xF0;
 							else entry->effectvalue = length >> 2;
-						} else if (version == PSMV_NEW) {
+						} else /*if (version == PSMV_NEW)*/ {
 							entry->effectvalue = length;
 						}
 						break;
@@ -351,7 +351,7 @@
 						if (version == PSMV_OLD) {
 							if (length < 4) entry->effectvalue = length | 0xF0;
 							else entry->effectvalue = length >> 2;
-						} else if (version == PSMV_NEW) {
+						} else /*if (version == PSMV_NEW)*/ {
 							entry->effectvalue = length;
 						}
 						break;
@@ -359,7 +359,7 @@
 					case 15:
 						entry->effect = IT_TONE_PORTAMENTO;
 						if (version == PSMV_OLD) entry->effectvalue = length >> 2;
-						else if (version == PSMV_NEW) entry->effectvalue = length;
+						else /*if (version == PSMV_NEW)*/ entry->effectvalue = length;
 						break;
 
 					case 0x15:
@@ -692,7 +692,7 @@
 							memcpy(event[n_events].data, ptr + 1, 4);
 							ptr += 5;
 							length -= 5;
-						} else if (found == PSMV_NEW) {
+						} else /*if (found == PSMV_NEW)*/ {
 							if (length < 9) goto error_ev;
 							memcpy(event[n_events].data, ptr + 1, 8);
 							ptr += 9;
@@ -812,7 +812,7 @@
 							n_patterns++;
 							break;
 						}
-					} else if (found == PSMV_NEW) {
+					} else /*if (found == PSMV_NEW)*/ {
 						if (length < 12) goto error_ev;
 						if (!pattcmp(ptr + 4, e->data, 8)) {
 							if (it_psm_process_pattern(&sigdata->pattern[n_patterns], ptr, length, speed, bpm, pan, vol, found)) goto error_ev;
@@ -1223,8 +1223,8 @@
 
 	if ( i < l )
 	{
-		na = strtoul( a + i, &p, 10 );
-		if ( p == a + i ) return 1;
+		na = strtoul( (const char *)a + i, &p, 10 );
+		if ( (const unsigned char *)p == a + i ) return 1;
 	}
 
 	for ( j = 0; j < l; ++j )
@@ -1234,8 +1234,8 @@
 
 	if ( j < l )
 	{
-		nb = strtoul( b + j, &p, 10 );
-		if ( p == b + j ) return -1;
+		nb = strtoul( (const char *)b + j, &p, 10 );
+		if ( (const unsigned char *)p == b + j ) return -1;
 	}
 
 	if ( i < j ) return -1;