cleanup error-handling in SDL_bmp.c - add missing error-message in SDL_LoadBMP_RW - check return value of SDL_RWtell in SDL_LoadBMP_RW - use standard SDL_EFREAD error instead of custom strings + adjust return type of readRlePixels
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
diff --git a/src/video/SDL_bmp.c b/src/video/SDL_bmp.c
index 5bddd73..0987f54 100644
--- a/src/video/SDL_bmp.c
+++ b/src/video/SDL_bmp.c
@@ -53,7 +53,7 @@
#define LCS_WINDOWS_COLOR_SPACE 0x57696E20
#endif
-static int readRlePixels(SDL_Surface * surface, SDL_RWops * src, int isRle8)
+static SDL_bool readRlePixels(SDL_Surface * surface, SDL_RWops * src, int isRle8)
{
/*
| Sets the surface pixels from src. A bmp image is upside down.
@@ -70,14 +70,14 @@ static int readRlePixels(SDL_Surface * surface, SDL_RWops * src, int isRle8)
#define COPY_PIXEL(x) spot = &bits[ofs++]; if(spot >= start && spot < end) *spot = (x)
for (;;) {
- if (!SDL_RWread(src, &ch, 1, 1)) return 1;
+ if (!SDL_RWread(src, &ch, 1, 1)) return SDL_TRUE;
/*
| encoded mode starts with a run length, and then a byte
| with two colour indexes to alternate between for the run
*/
if (ch) {
Uint8 pixel;
- if (!SDL_RWread(src, &pixel, 1, 1)) return 1;
+ if (!SDL_RWread(src, &pixel, 1, 1)) return SDL_TRUE;
if (isRle8) { /* 256-color bitmap, compressed */
do {
COPY_PIXEL(pixel);
@@ -98,18 +98,18 @@ static int readRlePixels(SDL_Surface * surface, SDL_RWops * src, int isRle8)
| a cursor move, or some absolute data.
| zero tag may be absolute mode or an escape
*/
- if (!SDL_RWread(src, &ch, 1, 1)) return 1;
+ if (!SDL_RWread(src, &ch, 1, 1)) return SDL_TRUE;
switch (ch) {
case 0: /* end of line */
ofs = 0;
bits -= pitch; /* go to previous */
break;
case 1: /* end of bitmap */
- return 0; /* success! */
+ return SDL_FALSE; /* success! */
case 2: /* delta */
- if (!SDL_RWread(src, &ch, 1, 1)) return 1;
+ if (!SDL_RWread(src, &ch, 1, 1)) return SDL_TRUE;
ofs += ch;
- if (!SDL_RWread(src, &ch, 1, 1)) return 1;
+ if (!SDL_RWread(src, &ch, 1, 1)) return SDL_TRUE;
bits -= (ch * pitch);
break;
default: /* no compression */
@@ -117,14 +117,14 @@ static int readRlePixels(SDL_Surface * surface, SDL_RWops * src, int isRle8)
needsPad = (ch & 1);
do {
Uint8 pixel;
- if (!SDL_RWread(src, &pixel, 1, 1)) return 1;
+ if (!SDL_RWread(src, &pixel, 1, 1)) return SDL_TRUE;
COPY_PIXEL(pixel);
} while (--ch);
} else {
needsPad = (((ch+1)>>1) & 1); /* (ch+1)>>1: bytes size */
for (;;) {
Uint8 pixel;
- if (!SDL_RWread(src, &pixel, 1, 1)) return 1;
+ if (!SDL_RWread(src, &pixel, 1, 1)) return SDL_TRUE;
COPY_PIXEL(pixel >> 4);
if (!--ch) break;
COPY_PIXEL(pixel & 0x0F);
@@ -132,7 +132,7 @@ static int readRlePixels(SDL_Surface * surface, SDL_RWops * src, int isRle8)
}
}
/* pad at even boundary */
- if (needsPad && !SDL_RWread(src, &ch, 1, 1)) return 1;
+ if (needsPad && !SDL_RWread(src, &ch, 1, 1)) return SDL_TRUE;
break;
}
}
@@ -213,12 +213,17 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
surface = NULL;
was_error = SDL_FALSE;
if (src == NULL) {
+ SDL_InvalidParamError("src");
was_error = SDL_TRUE;
goto done;
}
/* Read in the BMP file header */
fp_offset = SDL_RWtell(src);
+ if (fp_offset < 0) {
+ was_error = SDL_TRUE;
+ goto done;
+ }
SDL_ClearError();
if (SDL_RWread(src, magic, 1, 2) != 2) {
SDL_Error(SDL_EFREAD);
@@ -451,8 +456,8 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
goto done;
}
if ((biCompression == BI_RLE4) || (biCompression == BI_RLE8)) {
- was_error = (SDL_bool)readRlePixels(surface, src, biCompression == BI_RLE8);
- if (was_error) SDL_SetError("Error reading from BMP");
+ was_error = readRlePixels(surface, src, biCompression == BI_RLE8);
+ if (was_error) SDL_Error(SDL_EFREAD);
goto done;
}
top = (Uint8 *)surface->pixels;
@@ -484,7 +489,7 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
for (i = 0; i < surface->w; ++i) {
if (i % (8 / ExpandBMP) == 0) {
if (!SDL_RWread(src, &pixel, 1, 1)) {
- SDL_SetError("Error reading from BMP");
+ SDL_Error(SDL_EFREAD);
was_error = SDL_TRUE;
goto done;
}