Commits

Anonymous committed 002ceb5

Ensure a big enough buffer to hold the Lua script chunks dumped to memory.

  • Participants
  • Parent commits d587c29

Comments (0)

Files changed (1)

File LuaFortran/wrap_lua_dump.c

 
   if ( sz + dat->length > dat->space ) {
     // Increase the size of the buffer, if needed.
-    dat->container = realloc(dat->container, dat->space*2);
+    dat->space = ((dat->space*2) > (sz + dat->length))
+               ? (dat->space*2) : (sz + dat->length);
+    dat->container = realloc(dat->container, dat->space);
     if (!dat->container) return -10;
-    dat->space = dat->space*2;
   }
 
   // Append the data to write into the buffer.
   size_t sz;
 
   dat.length = 0;
-  dat.space = 4096;
+  dat.space = 1024;
   dat.container = malloc(dat.space);
 
   errcode = lua_dump(L, buf_writer, &dat);