From b04e82bd1938ce5e897b7009e69535f43a57212d Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 4 Jan 2004 22:04:38 +0000 Subject: [PATCH] Added checks for NULL data sources to individual loaders. Apps shouldn't be calling them, but they do. Naughty naughty! :) --- IMG_jpg.c | 5 +++++ IMG_lbm.c | 4 ++++ IMG_pcx.c | 4 ++++ IMG_png.c | 5 +++++ IMG_pnm.c | 5 +++++ IMG_tga.c | 5 +++++ IMG_tif.c | 4 ++++ IMG_xcf.c | 5 +++++ IMG_xpm.c | 4 ++++ IMG_xxx.c | 4 ++++ 10 files changed, 45 insertions(+) diff --git a/IMG_jpg.c b/IMG_jpg.c index 7cd766dc..4a0e9279 100644 --- a/IMG_jpg.c +++ b/IMG_jpg.c @@ -197,6 +197,11 @@ SDL_Surface *IMG_LoadJPG_RW(SDL_RWops *src) SDL_Surface *volatile surface = NULL; struct my_error_mgr jerr; + if ( !src ) { + /* The error message has been set in SDL_RWFromFile */ + return NULL; + } + /* Create a decompression structure and load the JPEG header */ cinfo.err = jpeg_std_error(&jerr.errmgr); jerr.errmgr.error_exit = my_error_exit; diff --git a/IMG_lbm.c b/IMG_lbm.c index f1b6e9dd..2b7cc60f 100644 --- a/IMG_lbm.c +++ b/IMG_lbm.c @@ -94,6 +94,10 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src ) error = NULL; MiniBuf = NULL; + if ( !src ) { + /* The error message has been set in SDL_RWFromFile */ + return NULL; + } if ( !SDL_RWread( src, id, 4, 1 ) ) { error="error reading IFF chunk"; diff --git a/IMG_pcx.c b/IMG_pcx.c index ee8765f1..8df1e5b2 100644 --- a/IMG_pcx.c +++ b/IMG_pcx.c @@ -96,6 +96,10 @@ SDL_Surface *IMG_LoadPCX_RW(SDL_RWops *src) char *error = NULL; int bits, src_bits; + if ( !src ) { + /* The error message has been set in SDL_RWFromFile */ + return NULL; + } if ( ! SDL_RWread(src, &pcxh, sizeof(pcxh), 1) ) { error = "file truncated"; goto done; diff --git a/IMG_png.c b/IMG_png.c index b40d9770..a4601726 100644 --- a/IMG_png.c +++ b/IMG_png.c @@ -111,6 +111,11 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src) volatile int ckey = -1; png_color_16 *transv; + if ( !src ) { + /* The error message has been set in SDL_RWFromFile */ + return NULL; + } + /* Initialize the data we will clean up when we're done */ png_ptr = NULL; info_ptr = NULL; row_pointers = NULL; surface = NULL; diff --git a/IMG_pnm.c b/IMG_pnm.c index 4047fe5d..ee3febc4 100644 --- a/IMG_pnm.c +++ b/IMG_pnm.c @@ -108,6 +108,11 @@ SDL_Surface *IMG_LoadPNM_RW(SDL_RWops *src) #define ERROR(s) do { error = (s); goto done; } while(0) + if ( !src ) { + /* The error message has been set in SDL_RWFromFile */ + return NULL; + } + SDL_RWread(src, magic, 2, 1); kind = magic[1] - '1'; ascii = 1; diff --git a/IMG_tga.c b/IMG_tga.c index dc9242ff..97ac78f3 100644 --- a/IMG_tga.c +++ b/IMG_tga.c @@ -107,6 +107,11 @@ SDL_Surface *IMG_LoadTGA_RW(SDL_RWops *src) Uint32 pixel; int count, rep; + if ( !src ) { + /* The error message has been set in SDL_RWFromFile */ + return NULL; + } + if(!SDL_RWread(src, &hdr, sizeof(hdr), 1)) goto error; ncols = LE16(hdr.cmap_len); diff --git a/IMG_tif.c b/IMG_tif.c index 960af135..2b28343a 100644 --- a/IMG_tif.c +++ b/IMG_tif.c @@ -110,6 +110,10 @@ SDL_Surface* IMG_LoadTIF_RW(SDL_RWops* src) Uint32 x, y; Uint32 half; + if ( !src ) { + /* The error message has been set in SDL_RWFromFile */ + return NULL; + } /* turn off memory mapped access with the m flag */ tiff = TIFFClientOpen("SDL_image", "rm", (thandle_t)src, diff --git a/IMG_xcf.c b/IMG_xcf.c index d5795787..135ef4e7 100644 --- a/IMG_xcf.c +++ b/IMG_xcf.c @@ -678,6 +678,11 @@ SDL_Surface *IMG_LoadXCF_RW(SDL_RWops *src) { unsigned char * (* load_tile) (SDL_RWops *, Uint32, int, int, int); + if ( !src ) { + /* The error message has been set in SDL_RWFromFile */ + return NULL; + } + /* Initialize the data we will clean up when we're done */ surface = NULL; read_error = 0; diff --git a/IMG_xpm.c b/IMG_xpm.c index 312c87a8..c2311f81 100644 --- a/IMG_xpm.c +++ b/IMG_xpm.c @@ -456,6 +456,10 @@ static SDL_Surface *load_xpm(char **xpm, SDL_RWops *src) /* Load a XPM type image from an RWops datasource */ SDL_Surface *IMG_LoadXPM_RW(SDL_RWops *src) { + if ( !src ) { + /* The error message has been set in SDL_RWFromFile */ + return NULL; + } return load_xpm(NULL, src); } diff --git a/IMG_xxx.c b/IMG_xxx.c index 558970a9..10de62ff 100644 --- a/IMG_xxx.c +++ b/IMG_xxx.c @@ -43,6 +43,10 @@ int IMG_isXXX(SDL_RWops *src) /* Load a XXX type image from an SDL datasource */ SDL_Surface *IMG_LoadXXX_RW(SDL_RWops *src) { + if ( !src ) { + /* The error message has been set in SDL_RWFromFile */ + return NULL; + } return(NULL); }