From ab1c924388247c8eff081381645440a6b378b003 Mon Sep 17 00:00:00 2001 From: cpq Date: Mon, 22 Mar 2021 11:30:29 +0000 Subject: [PATCH] Better check in mg_iobuf_resize() --- src/iobuf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/iobuf.c b/src/iobuf.c index 2530082e..6996f13d 100644 --- a/src/iobuf.c +++ b/src/iobuf.c @@ -14,7 +14,8 @@ int mg_iobuf_resize(struct mg_iobuf *io, size_t new_size) { // porting to some obscure platforms like FreeRTOS void *p = malloc(new_size); if (p != NULL) { - memcpy(p, io->buf, io->size < new_size ? io->size : new_size); + size_t len = new_size < io->len ? new_size : io->len; + if (len > 0) memcpy(p, io->buf, len); free(io->buf); io->buf = (unsigned char *) p; io->size = new_size;