(svn r6793) -Fix(5464): When checking items on an array, make sure to respect boundaries(jez).
authorbelugas
Tue, 17 Oct 2006 03:39:30 +0000
changeset 4867 b6360e8e4a12
parent 4866 8d19f2ac318e
child 4868 846811004d30
(svn r6793) -Fix(5464): When checking items on an array, make sure to respect boundaries(jez).
Made some comments code style compliant
music_gui.c
--- a/music_gui.c	Mon Oct 16 21:30:08 2006 +0000
+++ b/music_gui.c	Tue Oct 17 03:39:30 2006 +0000
@@ -49,14 +49,11 @@
 	byte *p = b;
 	byte t;
 
-	// empty playlist
-	if (b[0] == 0) return;
+	if (b[0] == 0) return; // empty playlist
 
-	// find the end
-	do p++; while (p[0] != 0);
+	do p++; while (p[0] != 0); // find the end
 
-	// and copy the bytes
-	t = *--p;
+	t = *--p; // and copy the bytes
 	while (p != b) {
 		p--;
 		p[1] = p[0];
@@ -109,13 +106,16 @@
 
 	memset(_cur_playlist, 0, sizeof(_cur_playlist));
 	do {
-		snprintf(filename, sizeof(filename),  "%s%s",
-		_path.gm_dir, origin_songs_specs[_playlists[msf.playlist][i]].filename);
-		//we are now checking for the existence of that file prior
-		//to add it to the list of available songs
-		if (FileExists(filename)) {
-			_cur_playlist[j] = _playlists[msf.playlist][i];
-			j++;
+		if (_playlists[msf.playlist][i] != 0) {  // Don't evaluate playlist terminator
+			snprintf(filename, sizeof(filename),  "%s%s",
+				_path.gm_dir, origin_songs_specs[(_playlists[msf.playlist][i]) - 1].filename);
+
+			/* we are now checking for the existence of that file prior
+			 * to add it to the list of available songs */
+			if (FileExists(filename)) {
+				_cur_playlist[j] = _playlists[msf.playlist][i];
+				j++;
+			}
 		}
 	} while (_playlists[msf.playlist][i++] != 0 && i < lengthof(_cur_playlist) - 1);
 
@@ -147,9 +147,9 @@
 {
 	if (_cur_playlist[0] == 0) {
 		SelectSongToPlay();
-		//if there is not songs in the playlist, it may indicate
-		//no file on the gm folder, or even no gm folder.
-		//Stop the playback, then
+		/* if there is not songs in the playlist, it may indicate
+		 * no file on the gm folder, or even no gm folder.
+		 * Stop the playback, then */
 		if (_cur_playlist[0] == 0) {
 			_song_is_active = false;
 			_music_wnd_cursong = 0;
@@ -241,7 +241,7 @@
 
 	case WE_CLICK:
 		switch (e->we.click.widget) {
-		case 3: { /* add to playlist */
+		case 3: { // add to playlist
 			int y = (e->we.click.pt.y - 23) / 6;
 			uint i;
 			byte *p;
@@ -261,7 +261,7 @@
 			}
 		} break;
 
-		case 4: { /* remove from playlist */
+		case 4: { // remove from playlist
 			int y = (e->we.click.pt.y - 23) / 6;
 			uint i;
 			byte *p;
@@ -278,7 +278,7 @@
 			SelectSongToPlay();
 		} break;
 
-		case 11: /* clear */
+		case 11: // clear
 			_playlists[msf.playlist][0] = 0;
 			SetWindowDirty(w);
 			StopMusic();
@@ -286,7 +286,7 @@
 			break;
 
 #if 0
-		case 12: /* save */
+		case 12: // save
 			ShowInfo("MusicTrackSelectionWndProc:save not implemented\n");
 			break;
 #endif