From 85453198b68c61ad583ea9653e46c998e7defa5c Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Thu, 10 Apr 2025 18:41:11 +0200 Subject: [PATCH] test: use calloc() instead of malloc() Using calloc() instead of malloc() as preventive measure, so there never can be any hidden bugs or leaks due uninitialized memory. The extra cost of using this compiler intrinsic should be practically impossible to measure - in many cases a good compiler can even deduce if certain areas really don't need to be zero'd (because they're written to right after allocation) and create more efficient machine code. The code pathes in question are pretty cold anyways, so it's probably not worth even thinking about potential extra runtime costs. Signed-off-by: Enrico Weigelt, metux IT consult --- test/damage/primitives.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/damage/primitives.c b/test/damage/primitives.c index d60da8d04..c16c28c78 100644 --- a/test/damage/primitives.c +++ b/test/damage/primitives.c @@ -75,8 +75,7 @@ get_image(struct test_setup *setup, xcb_drawable_t drawable) assert(reply->depth == 24); assert(len == 4 * setup->width * setup->height); - uint32_t *result = malloc(sizeof(uint32_t) * - setup->width * setup->height); + uint32_t *result = calloc(setup->width * setup->height, sizeof(uint32_t)); memcpy(result, data, len); free(reply);