From a272bc422754fc91d4cfb6e626829301febdae9e Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Fri, 17 Jun 2016 15:54:53 +0300 Subject: [PATCH] test/buffer: evbuffer_add_buffer() with empty chains Reported-by: @EMPanisset Link: https://github.com/libevent/libevent/issues/358#issuecomment-225345697 --- test/regress_buffer.c | 62 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/test/regress_buffer.c b/test/regress_buffer.c index 3b8f6f94..2f57c3b5 100644 --- a/test/regress_buffer.c +++ b/test/regress_buffer.c @@ -405,6 +405,66 @@ test_evbuffer_remove_buffer_with_empty3(void *ptr) evbuffer_free(buf); } +static void +test_evbuffer_add_buffer_with_empty(void *ptr) +{ + struct evbuffer *src = evbuffer_new(); + struct evbuffer *dst = evbuffer_new(); + struct evbuffer *buf = evbuffer_new(); + + evbuffer_add(buf, "foo", 3); + + evbuffer_add_reference(src, "foo", 3, NULL, NULL); + evbuffer_add_reference(src, NULL, 0, NULL, NULL); + evbuffer_add_buffer(src, buf); + + evbuffer_add(buf, "foo", 3); + + evbuffer_add_reference(dst, "foo", 3, NULL, NULL); + evbuffer_add_reference(dst, NULL, 0, NULL, NULL); + evbuffer_add_buffer(dst, buf); + + tt_int_op(evbuffer_get_length(src), ==, 6); + tt_int_op(evbuffer_get_length(dst), ==, 6); + + evbuffer_validate(src); + evbuffer_validate(dst); + + end: + evbuffer_free(src); + evbuffer_free(dst); + evbuffer_free(buf); +} + +static void +test_evbuffer_add_buffer_with_empty2(void *ptr) +{ + struct evbuffer *src = evbuffer_new(); + struct evbuffer *dst = evbuffer_new(); + struct evbuffer *buf = evbuffer_new(); + + evbuffer_add(buf, "foo", 3); + + evbuffer_add_reference(src, NULL, 0, NULL, NULL); + evbuffer_add_buffer(src, buf); + + evbuffer_add(buf, "foo", 3); + + evbuffer_add_reference(dst, NULL, 0, NULL, NULL); + evbuffer_add_buffer(dst, buf); + + tt_int_op(evbuffer_get_length(src), ==, 3); + tt_int_op(evbuffer_get_length(dst), ==, 3); + + evbuffer_validate(src); + evbuffer_validate(dst); + + end: + evbuffer_free(src); + evbuffer_free(dst); + evbuffer_free(buf); +} + static void test_evbuffer_reserve2(void *ptr) { @@ -2427,6 +2487,8 @@ struct testcase_t evbuffer_testcases[] = { { "remove_buffer_with_empty", test_evbuffer_remove_buffer_with_empty, 0, NULL, NULL }, { "remove_buffer_with_empty2", test_evbuffer_remove_buffer_with_empty2, 0, NULL, NULL }, { "remove_buffer_with_empty3", test_evbuffer_remove_buffer_with_empty3, 0, NULL, NULL }, + { "add_buffer_with_empty", test_evbuffer_add_buffer_with_empty, 0, NULL, NULL }, + { "add_buffer_with_empty2", test_evbuffer_add_buffer_with_empty2, 0, NULL, NULL }, { "reserve2", test_evbuffer_reserve2, 0, NULL, NULL }, { "reserve_many", test_evbuffer_reserve_many, 0, NULL, NULL }, { "reserve_many2", test_evbuffer_reserve_many, 0, &nil_setup, (void*)"add" }, -- 2.40.0