More error checking, and null terminate strings...
authorSam Lantinga <slouken@libsdl.org>
Fri, 28 Sep 2018 21:01:43 -0700
changeset 593cec9b7594f75
parent 592 31263a049d50
child 594 693d8aff87d8
More error checking, and null terminate strings...
IMG_xcf.c
     1.1 --- a/IMG_xcf.c	Fri Sep 28 22:00:26 2018 +0200
     1.2 +++ b/IMG_xcf.c	Fri Sep 28 21:01:43 2018 -0700
     1.3 @@ -224,16 +224,17 @@
     1.4    Uint32 tmp;
     1.5    char * data;
     1.6  
     1.7 -  tmp = SDL_ReadBE32 (src);
     1.8 +  tmp = SDL_ReadBE32(src);
     1.9    Sint64 remaining = SDL_RWsize(src) - SDL_RWtell(src);
    1.10 -  if (tmp > 0 && tmp < remaining) {
    1.11 +  if (tmp > 0 && tmp <= remaining) {
    1.12      data = (char *) SDL_malloc (sizeof (char) * tmp);
    1.13 -    SDL_RWread (src, data, tmp, 1);
    1.14 -  }
    1.15 -  else {
    1.16 +    if (data) {
    1.17 +      SDL_RWread(src, data, tmp, 1);
    1.18 +      data[tmp - 1] = '\0';
    1.19 +    }
    1.20 +  } else {
    1.21      data = NULL;
    1.22    }
    1.23 -
    1.24    return data;
    1.25  }
    1.26