Skip to content

Commit

Permalink
Fixed bugs 1914, 1915 - sizeof(const char**) is suspicious
Browse files Browse the repository at this point in the history
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 *));
  • Loading branch information
slouken committed Jun 18, 2013
1 parent 67aade6 commit b436db8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mixer.c
Expand Up @@ -127,7 +127,7 @@ const char *Mix_GetChunkDecoder(int index)

static void add_chunk_decoder(const char *decoder)
{
void *ptr = SDL_realloc((void *)chunk_decoders, (num_decoders + 1) * sizeof (const char **));
void *ptr = SDL_realloc((void *)chunk_decoders, (num_decoders + 1) * sizeof (const char *));
if (ptr == NULL) {
return; /* oh well, go on without it. */
}
Expand Down
2 changes: 1 addition & 1 deletion music.c
Expand Up @@ -163,7 +163,7 @@ const char *Mix_GetMusicDecoder(int index)

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

0 comments on commit b436db8

Please sign in to comment.