[Commits] SDL_image: More error checking, and null terminate strings...

libsdl.org revision control commits-owner at libsdl.org
Fri Sep 28 21:01:53 PDT 2018


details:   https://hg.libsdl.org/SDL_image/rev/cec9b7594f75
changeset: 593:cec9b7594f75
user:      Sam Lantinga <slouken at libsdl.org>
date:      Fri Sep 28 21:01:43 2018 -0700
description:
More error checking, and null terminate strings...

diffstat:

 IMG_xcf.c |  13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)

diffs (27 lines):

diff -r 31263a049d50 -r cec9b7594f75 IMG_xcf.c
--- a/IMG_xcf.c	Fri Sep 28 22:00:26 2018 +0200
+++ b/IMG_xcf.c	Fri Sep 28 21:01:43 2018 -0700
@@ -224,16 +224,17 @@
   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;
 }
 


More information about the commits mailing list