bug: fgets

"Andreas K. Foerster" <[email protected]> Mon, 7 Jul 2014 19:04:44 +0200
Newsgroups gmane.linux.lib.dietlibc
Message-ID <[email protected]>
Hello,

the function fgets doesn't terminate the string when no
line break (\n) is found.


This patch should fix it.

--- libstdio/fgets.old  2012-06-20 14:58:07.000000000 +0200
+++ libstdio/fgets.c    2014-07-07 17:55:38.508913504 +0200
@@ -2,6 +2,7 @@

 char *fgets_unlocked(char *s, int size, FILE *stream) {
   int l;
+  --size;
   for (l=0; l<size; ) {
     register int c;
     if (l && __likely(stream->bm<stream->bs)) {
@@ -16,12 +17,12 @@
     }
     s[l]=c;
     ++l;
-    if (c=='\n') {
-fini:
-      s[l]=0;
+    if (c=='\n')
       break;
-    }
   }
+
+fini:
+  s[l]=0;
   return s;
 }

-- 
AKFoerster <http://AKFoerster.de/>