Skip to contentSkip to conversation

ringtest: ring.c malloc & memset to calloc

PATCH New Peter Malone 1 participant 1 message Feb 16, 2017 virtio core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ringtest: ring.c malloc & memset to calloc

Code cleanup change - moving from malloc & memset to calloc.

---
 tools/virtio/ringtest/ring.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
tools/virtio/ringtest/ring.c +2 -4
index 747c5dd..fa92638 100644
@@ -84,12 +84,11 @@ void alloc_ring(void)
 		perror("Unable to allocate ring buffer.\n");
 		exit(3);
 	}
-	event = malloc(sizeof *event);
+	event = calloc(1, sizeof(*event));
 	if (!event) {
 		perror("Unable to allocate event buffer.\n");
 		exit(3);
 	}
-	memset(event, 0, sizeof *event);
 	guest.avail_idx = 0;
 	guest.kicked_avail_idx = -1;
 	guest.last_used_idx = 0;
@@ -102,12 +101,11 @@ void alloc_ring(void)
 		ring[i] = desc;
 	}
 	guest.num_free = ring_size;
-	data = malloc(ring_size * sizeof *data);
+	data = calloc(ring_size, sizeof(*data));
 	if (!data) {
 		perror("Unable to allocate data buffer.\n");
 		exit(3);
 	}
-	memset(data, 0, ring_size * sizeof *data);
 }
 
 /* guest side */
Signature · 1 line
1.7.10.4