Discussion:
bug: fgets
Andreas K. Foerster
2014-07-07 17:04:44 UTC
Permalink
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/>
Felix von Leitner
2014-07-07 18:54:54 UTC
Permalink
Post by Andreas K. Foerster
the function fgets doesn't terminate the string when no
line break (\n) is found.
Fixed in CVS. How embarrassing!

Thanks,
Felix

Loading...