From bed46b55c06a3488971fda8271cf9fc0e3dd84d5 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 20 Nov 2022 11:07:30 -0800 Subject: Use calloc instead of malloc to allocate arrays Makes code more consistent with other functions in this library which already do this and adds extra protection against overflows or failures to properly fill in values. Signed-off-by: Alan Coopersmith --- src/XRes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/XRes.c b/src/XRes.c index d061dd7..af89f77 100644 --- a/src/XRes.c +++ b/src/XRes.c @@ -113,7 +113,7 @@ XResQueryClients(Display *dpy, int *num_clients, XResClient **clients) XResClient *clnts; if (rep.num_clients < (INT_MAX / sizeof(XResClient))) - clnts = Xmalloc(sizeof(XResClient) * rep.num_clients); + clnts = Xcalloc(rep.num_clients, sizeof(XResClient)); else clnts = NULL; @@ -168,7 +168,7 @@ XResQueryClientResources(Display *dpy, XID xid, XResType *typs; if (rep.num_types < (INT_MAX / sizeof(XResType))) - typs = Xmalloc(sizeof(XResType) * rep.num_types); + typs = Xcalloc(rep.num_types, sizeof(XResType)); else typs = NULL; -- cgit v1.2.1