diff --git a/mongoose.c b/mongoose.c index 9eff992c..616e3f1e 100644 --- a/mongoose.c +++ b/mongoose.c @@ -2608,6 +2608,7 @@ int mg_iobuf_resize(struct mg_iobuf *io, size_t new_size) { mg_free(io->buf); io->buf = (unsigned char *) p; io->size = new_size; + io->len = len; } else { ok = 0; MG_ERROR(("%lld->%lld", (uint64_t) io->size, (uint64_t) new_size)); diff --git a/src/iobuf.c b/src/iobuf.c index 390e9ce2..4d83f4cd 100644 --- a/src/iobuf.c +++ b/src/iobuf.c @@ -25,6 +25,7 @@ int mg_iobuf_resize(struct mg_iobuf *io, size_t new_size) { mg_free(io->buf); io->buf = (unsigned char *) p; io->size = new_size; + io->len = len; } else { ok = 0; MG_ERROR(("%lld->%lld", (uint64_t) io->size, (uint64_t) new_size)); diff --git a/test/unit_test.c b/test/unit_test.c index ee135a7e..4ec3889f 100644 --- a/test/unit_test.c +++ b/test/unit_test.c @@ -322,6 +322,8 @@ static void test_iobuf(void) { mg_iobuf_add(&io, io.len, "a", 1); ASSERT(io.buf != NULL && io.size == 20 && io.len == 11); ASSERT(memcmp(io.buf, "xhi!123456a", io.len) == 0); + mg_iobuf_resize(&io, 1); + ASSERT(io.buf != NULL && io.size == 10 && io.len == 10); mg_iobuf_free(&io); }