X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=string.c;fp=string.c;h=d75dbac212a36a6f10ebb0e23a40bf54f580eaa6;hp=453a61c16e9b76dec4d5a427df2a3e6fff422e75;hb=e833dd12e607e9e5951a657d6e99f19adddefb7d;hpb=66cfa4ab3cd509b1b7d1b5fb860fc4644a2313ab diff --git a/string.c b/string.c index 453a61c1..d75dbac2 100644 --- a/string.c +++ b/string.c @@ -380,14 +380,13 @@ int for_each_line(unsigned flags, char *buf, size_t size, char *next_cr; next_cr = memchr(start, '\n', buf + size - start); - next_null = memchr(start, '\0', buf + size - start); + next_null = memchr(start, '\0', next_cr? + next_cr - start : buf + size - start); if (!next_cr && !next_null) break; - if (next_cr && next_null) { - end = next_cr < next_null? next_cr : next_null; - } else if (next_null) { + if (next_null) end = next_null; - } else + else end = next_cr; num_lines++; if (!(flags & FELF_DISCARD_FIRST) || start != buf) {