فهرست منبع

if numeral overflows the reading buffer, signal it as invalid input
(resulting in nil)

Roberto Ierusalimschy 11 سال پیش
والد
کامیت
e9d86eddf3
1فایلهای تغییر یافته به همراه5 افزوده شده و 3 حذف شده
  1. 5 3
      liolib.c

+ 5 - 3
liolib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: liolib.c,v 2.124 2014/05/15 15:21:06 roberto Exp $
+** $Id: liolib.c,v 2.125 2014/05/21 15:24:21 roberto Exp roberto $
 ** Standard I/O (and system) library
 ** See Copyright Notice in lua.h
 */
@@ -371,7 +371,7 @@ typedef struct {
   FILE *f;  /* file being read */
   int c;  /* current character (look ahead) */
   int n;  /* number of elements in buffer 'buff' */
-  char buff[MAXRN];
+  char buff[MAXRN + 1];  /* +1 for ending '\0' */
 } RN;
 
 
@@ -379,8 +379,10 @@ typedef struct {
 ** Add current char to buffer (if not out of space) and read next one
 */
 static int nextc (RN *rn) {
-  if (rn->n >= MAXRN)  /* buffer overflow? */
+  if (rn->n >= MAXRN) {  /* buffer overflow? */
+    rn->buff[0] = '\0';  /* invalidate result */
     return 0;  /* fail */
+  }
   else {
     rn->buff[rn->n++] = rn->c;  /* save current char */
     rn->c = l_getc(rn->f);  /* read next one */