Browse Source

asyncio: SDL_LoadFileAsync was not null-terminating the file data.

Ryan C. Gordon 4 weeks ago
parent
commit
10072bb07d
1 changed files with 3 additions and 2 deletions
  1. 3 2
      src/io/SDL_asyncio.c

+ 3 - 2
src/io/SDL_asyncio.c

@@ -309,12 +309,13 @@ bool SDL_LoadFileAsync(const char *file, SDL_AsyncIOQueue *queue, void *userdata
     if (asyncio) {
         asyncio->oneshot = true;
 
-        void *ptr = NULL;
+        Uint8 *ptr = NULL;
         const Sint64 flen = SDL_GetAsyncIOSize(asyncio);
         if (flen >= 0) {
             // !!! FIXME: check if flen > address space, since it'll truncate and we'll just end up with an incomplete buffer or a crash.
-            ptr = SDL_malloc((size_t) (flen + 1));  // over-allocate by one so we can add a null-terminator.
+            ptr = (Uint8 *) SDL_malloc((size_t) (flen + 1));  // over-allocate by one so we can add a null-terminator.
             if (ptr) {
+                ptr[flen] = '\0';
                 retval = SDL_ReadAsyncIO(asyncio, ptr, 0, (Uint64) flen, queue, userdata);
                 if (!retval) {
                     SDL_free(ptr);