We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1914 - sizeof(const char**) is suspicious in music.c file
Summary: sizeof(const char**) is suspicious in music.c file
Status: RESOLVED FIXED
Alias: None
Product: SDL_mixer
Classification: Unclassified
Component: misc (show other bugs)
Version: 1.2.12
Hardware: x86 Linux
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-15 07:06 UTC by Nitz
Modified: 2013-06-18 03:45 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nitz 2013-06-15 07:06:06 UTC
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 *));
Comment 1 Sam Lantinga 2013-06-18 03:45:08 UTC
Fixed, thanks!
http://hg.libsdl.org/SDL_mixer/rev/030181ff9f59