OSDN Git Service

fix buffer under run.
authortsntsumi <tsntsumi@users.sourceforge.jp>
Sat, 14 Aug 2010 15:23:53 +0000 (15:23 +0000)
committertsntsumi <tsntsumi@users.sourceforge.jp>
Sat, 14 Aug 2010 15:23:53 +0000 (15:23 +0000)
src/ccunit/CCUnitReadSuite.c

index 4d5d761..bc85b1c 100644 (file)
@@ -318,11 +318,23 @@ static int readline ()
   if (!sp)
     return 0;
   /* chomp CR/LF */
-  tail = line.str + line.length - 1;
-  while (*tail == '\n' || *tail == '\r')       /* for dos/mac? */
+  if (line.length > 0)
     {
-      line.length --;
-      *(tail --) = '\0';
+      tail = line.str + line.length - 1;
+      if (*tail == '\n')
+       {
+         line.length --;
+         *tail = '\0';
+         if (line.length > 0)
+           tail --;
+       }
+      if (*tail == '\r')       /* for dos and/or mac? */
+       {
+         line.length --;
+         *tail = '\0';
+         if (line.length > 0)
+           tail --;
+       }
     }
   line.lno ++;
   return 1;