From: Emden R. Gansner Date: Mon, 17 Jun 2013 21:41:10 +0000 (-0400) Subject: Fix bug 2296: logic was incorrect in do{}while loop. X-Git-Tag: LAST_LIBGRAPH~32^2~187 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e3d663e77a9a2f1aae6ed1031ddf7a59bae3c85b;p=graphviz Fix bug 2296: logic was incorrect in do{}while loop. --- diff --git a/lib/cgraph/io.c b/lib/cgraph/io.c index d6033a08c..c677c4f6b 100644 --- a/lib/cgraph/io.c +++ b/lib/cgraph/io.c @@ -112,10 +112,16 @@ memiofread(void *chan, char *buf, int bufsize) l = 0; ptr = s->data + s->cur; optr = buf; + /* We know we have at least one character */ + c = *ptr++; do { - *optr++ = c = *ptr++; + *optr++ = c; l++; - } while (c && (c != '\n') && (l < bufsize)); + /* continue if c is not newline, we have space in buffer, + * and next character is non-null (we are working with + * null-terminated strings. + */ + } while ((c != '\n') && (l < bufsize) && (c = *ptr++)); s->cur += l; return l; }