fix swprintf handling of nul character in output
[musl] / src / stdio / fgetln.c
index a2e4bd3..5748435 100644 (file)
@@ -1,3 +1,4 @@
+#define _GNU_SOURCE
 #include "stdio_impl.h"
 #include <string.h>
 
@@ -7,7 +8,7 @@ char *fgetln(FILE *f, size_t *plen)
        ssize_t l;
        FLOCK(f);
        ungetc(getc_unlocked(f), f);
-       if ((z=memchr(f->rpos, '\n', f->rend - f->rpos))) {
+       if (f->rend && (z=memchr(f->rpos, '\n', f->rend - f->rpos))) {
                ret = (char *)f->rpos;
                *plen = ++z - ret;
                f->rpos = (void *)z;