On Fri, Jun 20, 2014 at 04:34:19PM +0200, Manuel Giraud wrote: > + lbuf = NULL; > + while ((buf = fgetln(fp, &len))) { > + if (buf[len - 1] == '\n') { > + if (len == 1) > + continue; > + buf[len - 1] = '\0'; > + } else { > + len++; > + if ((lbuf = malloc(len)) == NULL) > + err(1, NULL); > + memcpy(lbuf, buf, len - 1); > + lbuf[len - 1] = '\0'; > + buf = lbuf; > + }
What is the rational behind checking for len == 1 in '\n' case, but not for "last line without new line"? If you want to skip empty lines, you should check after the if/else-block for buf[0] == '\0', imho. Tobias