Skip to content

Commit

Permalink
More error checking, and null terminate strings...
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Sep 29, 2018
1 parent 98e9457 commit 9413074
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions IMG_xcf.c
Expand Up @@ -224,16 +224,17 @@ static char * read_string (SDL_RWops * src) {
Uint32 tmp;
char * data;

tmp = SDL_ReadBE32 (src);
tmp = SDL_ReadBE32(src);
Sint64 remaining = SDL_RWsize(src) - SDL_RWtell(src);
if (tmp > 0 && tmp < remaining) {
if (tmp > 0 && tmp <= remaining) {
data = (char *) SDL_malloc (sizeof (char) * tmp);
SDL_RWread (src, data, tmp, 1);
}
else {
if (data) {
SDL_RWread(src, data, tmp, 1);
data[tmp - 1] = '\0';
}
} else {
data = NULL;
}

return data;
}

Expand Down

0 comments on commit 9413074

Please sign in to comment.