Fixed bug #819
authorSam Lantinga <slouken@libsdl.org>
Sat, 03 Oct 2009 08:46:55 +0000
changeset 4124c1f81481f87
parent 411 cade1e3a4cb8
child 413 e7c461178cd7
Fixed bug #819

O.Sezer 2009-10-02 08:41:50 PDT

SDL_mixer crashes in add_music_decoder() and add_chunk_decoder() due to a
thinko in the size argument in the realloc() calls: the initial value of
num_decoders is 0. Attached a quick fix. Regards.
mixer.c
music.c
     1.1 --- a/mixer.c	Sat Oct 03 08:09:27 2009 +0000
     1.2 +++ b/mixer.c	Sat Oct 03 08:46:55 2009 +0000
     1.3 @@ -117,7 +117,7 @@
     1.4  
     1.5  static void add_chunk_decoder(const char *decoder)
     1.6  {
     1.7 -	void *ptr = realloc(chunk_decoders, num_decoders * sizeof (const char **));
     1.8 +	void *ptr = realloc(chunk_decoders, (num_decoders + 1) * sizeof (const char **));
     1.9  	if (ptr == NULL) {
    1.10  		return;  /* oh well, go on without it. */
    1.11  	}
     2.1 --- a/music.c	Sat Oct 03 08:09:27 2009 +0000
     2.2 +++ b/music.c	Sat Oct 03 08:46:55 2009 +0000
     2.3 @@ -154,7 +154,7 @@
     2.4  
     2.5  static void add_music_decoder(const char *decoder)
     2.6  {
     2.7 -	void *ptr = realloc(music_decoders, num_decoders * sizeof (const char **));
     2.8 +	void *ptr = realloc(music_decoders, (num_decoders + 1) * sizeof (const char **));
     2.9  	if (ptr == NULL) {
    2.10  		return;  /* oh well, go on without it. */
    2.11  	}