summaryrefslogtreecommitdiff
path: root/liolib.c
diff options
context:
space:
mode:
Diffstat (limited to 'liolib.c')
-rw-r--r--liolib.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/liolib.c b/liolib.c
index b1fddebe..d71965a6 100644
--- a/liolib.c
+++ b/liolib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: liolib.c,v 1.87 2000/10/20 16:39:03 roberto Exp roberto $ 2** $Id: liolib.c,v 1.88 2000/10/26 12:47:05 roberto Exp roberto $
3** Standard I/O (and system) library 3** Standard I/O (and system) library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -345,9 +345,12 @@ static void read_file (lua_State *L, FILE *f) {
345 size_t size = BUFSIZ; 345 size_t size = BUFSIZ;
346 char *buffer = NULL; 346 char *buffer = NULL;
347 for (;;) { 347 for (;;) {
348 buffer = (char *)realloc(buffer, size); 348 char *newbuffer = (char *)realloc(buffer, size);
349 if (buffer == NULL) 349 if (newbuffer == NULL) {
350 free(buffer);
350 lua_error(L, "not enough memory to read a file"); 351 lua_error(L, "not enough memory to read a file");
352 }
353 buffer = newbuffer;
351 len += fread(buffer+len, sizeof(char), size-len, f); 354 len += fread(buffer+len, sizeof(char), size-len, f);
352 if (len < size) break; /* did not read all it could */ 355 if (len < size) break; /* did not read all it could */
353 size *= 2; 356 size *= 2;