diff options
| -rw-r--r-- | liolib.c | 8 |
1 files changed, 5 insertions, 3 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: liolib.c,v 2.124 2014/05/15 15:21:06 roberto Exp $ | 2 | ** $Id: liolib.c,v 2.125 2014/05/21 15:24:21 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 | */ |
| @@ -371,7 +371,7 @@ typedef struct { | |||
| 371 | FILE *f; /* file being read */ | 371 | FILE *f; /* file being read */ |
| 372 | int c; /* current character (look ahead) */ | 372 | int c; /* current character (look ahead) */ |
| 373 | int n; /* number of elements in buffer 'buff' */ | 373 | int n; /* number of elements in buffer 'buff' */ |
| 374 | char buff[MAXRN]; | 374 | char buff[MAXRN + 1]; /* +1 for ending '\0' */ |
| 375 | } RN; | 375 | } RN; |
| 376 | 376 | ||
| 377 | 377 | ||
| @@ -379,8 +379,10 @@ typedef struct { | |||
| 379 | ** Add current char to buffer (if not out of space) and read next one | 379 | ** Add current char to buffer (if not out of space) and read next one |
| 380 | */ | 380 | */ |
| 381 | static int nextc (RN *rn) { | 381 | static int nextc (RN *rn) { |
| 382 | if (rn->n >= MAXRN) /* buffer overflow? */ | 382 | if (rn->n >= MAXRN) { /* buffer overflow? */ |
| 383 | rn->buff[0] = '\0'; /* invalidate result */ | ||
| 383 | return 0; /* fail */ | 384 | return 0; /* fail */ |
| 385 | } | ||
| 384 | else { | 386 | else { |
| 385 | rn->buff[rn->n++] = rn->c; /* save current char */ | 387 | rn->buff[rn->n++] = rn->c; /* save current char */ |
| 386 | rn->c = l_getc(rn->f); /* read next one */ | 388 | rn->c = l_getc(rn->f); /* read next one */ |
