From e3d663e77a9a2f1aae6ed1031ddf7a59bae3c85b Mon Sep 17 00:00:00 2001 From: "Emden R. Gansner" Date: Mon, 17 Jun 2013 17:41:10 -0400 Subject: [PATCH] Fix bug 2296: logic was incorrect in do{}while loop. --- lib/cgraph/io.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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; } -- 2.40.0