With the virtio implementation vu_buffer is used for socket IO and therefore information about the current position after a write is required. buffer_grow uses realloc to extend the buffer, due to the fact that realloc doesn't guarantee that allocated memory is initialized there should be a memset. --- include/util.h | 1 + vhostmd/util.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/util.h b/include/util.h index 3a21e09..c0bd19a 100644 --- a/include/util.h +++ b/include/util.h @@ -42,6 +42,7 @@ typedef enum { typedef struct _vu_buffer { unsigned int size; unsigned int use; + unsigned int pos; char *content; }vu_buffer; diff --git a/vhostmd/util.c b/vhostmd/util.c index 70fc804..c0f8f2b 100644 --- a/vhostmd/util.c +++ b/vhostmd/util.c @@ -53,6 +53,7 @@ static int buffer_grow(vu_buffer *buf, int len) return -1; buf->size = size; + memset(&buf->content[buf->use], 0, len); return 0; } @@ -151,7 +152,7 @@ int vu_buffer_create(vu_buffer **buf, int len) *buf = calloc(1, sizeof(vu_buffer)); if (*buf == NULL) return -1; - + return buffer_grow(*buf, len); } @@ -232,6 +233,7 @@ void vu_buffer_erase(vu_buffer *buf) if (buf) { memset(buf->content, '\0', buf->size); buf->use = 0; + buf->pos = 0; } } -- 2.17.1 (Apple Git-112) _______________________________________________ virt-tools-list mailing list virt-tools-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/virt-tools-list