Fixed bugs 1914, 1915 - sizeof(const char**) is suspicious
authorSam Lantinga <slouken@libsdl.org>
Tue, 18 Jun 2013 00:44:41 -0700
changeset 644030181ff9f59
parent 643 5bf7568384a4
child 645 a17fb0ef7645
Fixed bugs 1914, 1915 - sizeof(const char**) is suspicious

Nitz

In function:
static void add_music_decoder(const char *decoder)
{
void *ptr = SDL_realloc(music_decoders, (num_decoders + 1) * sizeof (const char **));
if (ptr == NULL) {
return; /* oh well, go on without it. */
}
music_decoders = (const char **) ptr;
music_decoders[num_decoders++] = decoder;
}

Passing argument sizeof(char const **) to function SDL_realloc is suspicious.

Logically it should be sizeof(char const *) instead of sizeof (char const **)

In this particular case sizeof(char const **) happens to be equal to sizeof(char const *), but this is not a portable assumption.
It reduces the understanding of the user.

So Patch should be,
void *ptr=SDL_realloc(music_decoders,(num_decoders+1) * sizeof(const char *));
mixer.c
music.c
     1.1 --- a/mixer.c	Mon Jun 17 07:17:07 2013 -0700
     1.2 +++ b/mixer.c	Tue Jun 18 00:44:41 2013 -0700
     1.3 @@ -127,7 +127,7 @@
     1.4  
     1.5  static void add_chunk_decoder(const char *decoder)
     1.6  {
     1.7 -    void *ptr = SDL_realloc((void *)chunk_decoders, (num_decoders + 1) * sizeof (const char **));
     1.8 +    void *ptr = SDL_realloc((void *)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	Mon Jun 17 07:17:07 2013 -0700
     2.2 +++ b/music.c	Tue Jun 18 00:44:41 2013 -0700
     2.3 @@ -163,7 +163,7 @@
     2.4  
     2.5  static void add_music_decoder(const char *decoder)
     2.6  {
     2.7 -    void *ptr = SDL_realloc((void *)music_decoders, (num_decoders + 1) * sizeof (const char **));
     2.8 +    void *ptr = SDL_realloc((void *)music_decoders, (num_decoders + 1) * sizeof (const char *));
     2.9      if (ptr == NULL) {
    2.10          return;  /* oh well, go on without it. */
    2.11      }