From 8522cdc2264804d0677b7c0a447a0b45cf4195e3 Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Tue, 1 Sep 2015 22:13:45 +0200 Subject: iobuf: Fix test. * common/t-iobuf.c (content_filter): If there is nothing to read, don't forget to set *LEN to 0. (main): Fix checks. -- Signed-off-by: Neal H. Walfield . --- common/t-iobuf.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'common/t-iobuf.c') diff --git a/common/t-iobuf.c b/common/t-iobuf.c index ae72fde90..839798f0c 100644 --- a/common/t-iobuf.c +++ b/common/t-iobuf.c @@ -111,15 +111,14 @@ content_filter (void *opaque, int control, if (toread > remaining) toread = remaining; - if (toread == 0) - return -1; - memcpy (buf, &state->buffer[state->pos], toread); state->pos += toread; *len = toread; + if (toread == 0) + return -1; return 0; } @@ -269,10 +268,8 @@ main (int argc, char *argv[]) } { - /* - 3 characters plus new line - - 4 characters plus new line - - 5 characters plus new line - - 5 characters, no new line + /* - 10 characters, EOF + - 17 characters, EOF */ char *content = "abcdefghijklmnopq"; char *content2 = "0123456789"; @@ -294,7 +291,7 @@ main (int argc, char *argv[]) if (c == -1 && lastc == -1) { /* printf("Two EOFs in a row. Done.\n"); */ - assert (n == 44); + assert (n == 27); break; } @@ -303,7 +300,7 @@ main (int argc, char *argv[]) if (c == -1) { /* printf("After %d bytes, got EOF.\n", n); */ - assert (n == 27 || n == 44); + assert (n == 10 || n == 27); } else { -- cgit v1.2.3