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 2964

Summary: Remove NULL check in IMG_LoadTGA_RW function
Product: SDL_image Reporter: Nitz <nitin.j4>
Component: miscAssignee: Sam Lantinga <slouken>
Status: RESOLVED WONTFIX QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2    
Version: unspecified   
Hardware: x86   
OS: Linux   
Attachments: Patch is attached to remove extra NULL check for img

Description Nitz 2015-04-28 12:23:17 UTC
In IMG_LoadTGA_RW function:

if(img == NULL) {

        error = "Out of memory";

        goto error;

    }


error:
    SDL_RWseek(src, start, RW_SEEK_SET);
    if ( img ) {
        SDL_FreeSurface(img);
    }
    IMG_SetError("%s", error);
    return NULL;

Here again NULL check is applied for img, which is not required as its already checked. So its better to remove this extra code.

Patch is attached.
Comment 1 Nitz 2015-04-28 12:25:27 UTC
Created attachment 2138 [details]
Patch is attached to remove extra NULL check for img
Comment 2 Sam Lantinga 2015-05-03 02:37:04 UTC
This is useful in case anybody adds any additional error conditions in the function. It's not performance critical code so an extra conditional isn't a problem here.

Thanks for the analysis!