From 46c847e738be41d13611753921efe5cff0ad207e Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 19 Dec 2003 18:04:48 +0000 Subject: [PATCH] Date: Fri, 19 Dec 2003 18:47:46 +0200 From: "Mike Gorchak" Subject: SDL image I've fixed NULL pointer pass as RWops argument in all calls in the SDL_Image library, found that when porting toppler game to QNX6, they're do not checking any return pointers and then game failed in the SDL_image library internals, instead of fail in the toppler internals ;) And I've fixed the QNX6 .qpg file for automative package building. --- IMG.c | 12 ++++++++--- IMG_lbm.c | 2 -- IMG_pcx.c | 4 ---- IMG_png.c | 5 ----- IMG_pnm.c | 3 --- IMG_xcf.c | 5 ----- SDL_image.qpg.in | 52 ++++++++++++++++++++++++++++++++++++++---------- 7 files changed, 51 insertions(+), 32 deletions(-) diff --git a/IMG.c b/IMG.c index ec568439..45581173 100644 --- a/IMG.c +++ b/IMG.c @@ -39,7 +39,7 @@ static struct { SDL_Surface *(*load)(SDL_RWops *src); } supported[] = { /* keep magicless formats first */ - { "TGA", 0, IMG_LoadTGA_RW }, + { "TGA", NULL, IMG_LoadTGA_RW }, { "BMP", IMG_isBMP, IMG_LoadBMP_RW }, { "PNM", IMG_isPNM, IMG_LoadPNM_RW }, /* P[BGP]M share code */ { "XPM", IMG_isXPM, IMG_LoadXPM_RW }, @@ -64,8 +64,13 @@ SDL_Surface *IMG_Load(const char *file) { SDL_RWops *src = SDL_RWFromFile(file, "rb"); char *ext = strrchr(file, '.'); - if(ext) - ext++; + if(ext) { + ext++; + } + if(!src) { + /* The error message has been set in SDL_RWFromFile */ + return NULL; + } return IMG_LoadTyped_RW(src, 1, ext); } @@ -96,6 +101,7 @@ SDL_Surface *IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, char *type) /* Make sure there is something to do.. */ if ( src == NULL ) { + IMG_SetError("Passed a NULL data source"); return(NULL); } diff --git a/IMG_lbm.c b/IMG_lbm.c index 02d2fc82..49877f9b 100644 --- a/IMG_lbm.c +++ b/IMG_lbm.c @@ -91,8 +91,6 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src ) error = NULL; MiniBuf = NULL; - if ( src == NULL ) goto done; - if ( !SDL_RWread( src, id, 4, 1 ) ) { error="error reading IFF chunk"; diff --git a/IMG_pcx.c b/IMG_pcx.c index f0278dd0..5cdbb25c 100644 --- a/IMG_pcx.c +++ b/IMG_pcx.c @@ -96,10 +96,6 @@ SDL_Surface *IMG_LoadPCX_RW(SDL_RWops *src) char *error = NULL; int bits, src_bits; - if ( ! src ) { - goto done; - } - if ( ! SDL_RWread(src, &pcxh, sizeof(pcxh), 1) ) { error = "file truncated"; goto done; diff --git a/IMG_png.c b/IMG_png.c index 492ae0c4..b7403298 100644 --- a/IMG_png.c +++ b/IMG_png.c @@ -114,11 +114,6 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src) /* Initialize the data we will clean up when we're done */ png_ptr = NULL; info_ptr = NULL; row_pointers = NULL; surface = NULL; - /* Check to make sure we have something to do */ - if ( ! src ) { - goto done; - } - /* Create the PNG loading context structure */ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL,NULL,NULL); diff --git a/IMG_pnm.c b/IMG_pnm.c index 920461fd..a820ebec 100644 --- a/IMG_pnm.c +++ b/IMG_pnm.c @@ -108,9 +108,6 @@ SDL_Surface *IMG_LoadPNM_RW(SDL_RWops *src) #define ERROR(s) do { error = (s); goto done; } while(0) - if(!src) - return NULL; - SDL_RWread(src, magic, 2, 1); kind = magic[1] - '1'; ascii = 1; diff --git a/IMG_xcf.c b/IMG_xcf.c index aa41e10b..53baf239 100644 --- a/IMG_xcf.c +++ b/IMG_xcf.c @@ -678,11 +678,6 @@ SDL_Surface *IMG_LoadXCF_RW(SDL_RWops *src) { unsigned char * (* load_tile) (SDL_RWops *, Uint32, int, int, int); - /* Check to make sure we have something to do */ - if ( ! src ) { - return NULL; - } - /* Initialize the data we will clean up when we're done */ surface = NULL; read_error = 0; diff --git a/SDL_image.qpg.in b/SDL_image.qpg.in index 0601b24a..3508607b 100644 --- a/SDL_image.qpg.in +++ b/SDL_image.qpg.in @@ -37,6 +37,7 @@ + Library SDL_image @@ -44,6 +45,7 @@ http://qnx.org.ru/repository 2.0 + SDL_image SDL_image @@ -61,9 +63,10 @@ This is a simple library to load images of various formats as SDL surfaces. This library supports BMP, PPM, PCX, GIF, JPEG, PNG, and TIFF formats. This is a simple library to load images of various formats as SDL surfaces. This library supports BMP, PPM, PCX, GIF, JPEG, PNG, and TIFF formats. - http://www.libsdl.org + http://www.libsdl.org/projects/SDL_image + @VERSION@ High @@ -74,23 +77,52 @@ GNU General Public License + - Software Development/Libraries and Extensions/C Libraries + Software Development/Libraries and Extensions/C Libraries SDL, graphics, images, BMP, PPM, PCX, GIF, JPEG, PNG, TIFF - - qnx6 - qnx6 - Photon - Developer - User + none + Photon + Console + Developer + User repdata://LicenseUrl/COPYING + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + -