From dd8c77a0c0d62ab88cf96ac507562469a7bcbc5a Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 21 Jul 2024 11:10:44 -0700 Subject: Use calloc instead of malloc and manual loops to zero array contents Signed-off-by: Alan Coopersmith Part-of: --- src/Xv.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/Xv.c b/src/Xv.c index 5bb0589..2a7e6c5 100644 --- a/src/Xv.c +++ b/src/Xv.c @@ -204,22 +204,13 @@ XvQueryAdaptors( u.buffer = buffer; end = buffer + size; - size = rep.num_adaptors * sizeof(XvAdaptorInfo); - if ((pas = Xmalloc(size)) == NULL) { + if ((pas = Xcalloc(rep.num_adaptors, sizeof(XvAdaptorInfo))) == NULL) { status = XvBadAlloc; goto out; } /* INIT ADAPTOR FIELDS */ - pa = pas; - for (unsigned int ii = 0; ii < rep.num_adaptors; ii++) { - pa->num_adaptors = 0; - pa->name = (char *) NULL; - pa->formats = (XvFormat *) NULL; - pa++; - } - pa = pas; for (unsigned int ii = 0; ii < rep.num_adaptors; ii++) { char *name; @@ -255,8 +246,7 @@ XvQueryAdaptors( /* GET FORMATS */ - size = pa->num_formats * sizeof(XvFormat); - if ((pfs = Xmalloc(size)) == NULL) { + if ((pfs = Xcalloc(pa->num_formats, sizeof(XvFormat))) == NULL) { status = XvBadAlloc; goto out; } @@ -379,21 +369,13 @@ XvQueryEncodings( u.buffer = buffer; end = buffer + size; - size = rep.num_encodings * sizeof(XvEncodingInfo); - if ((pes = Xmalloc(size)) == NULL) { + if ((pes = Xcalloc(rep.num_encodings, sizeof(XvEncodingInfo))) == NULL) { status = XvBadAlloc; goto out; } /* INITIALIZE THE ENCODING POINTER */ - pe = pes; - for (unsigned int jj = 0; jj < rep.num_encodings; jj++) { - pe->name = (char *) NULL; - pe->num_encodings = 0; - pe++; - } - pe = pes; for (unsigned int jj = 0; jj < rep.num_encodings; jj++) { char *name; @@ -934,7 +916,7 @@ XvListImageFormats(Display *dpy, XvPortID port, int *num) if (rep.num_formats) { if (rep.num_formats < (INT_MAX / sizeof(XvImageFormatValues))) - ret = Xmalloc(rep.num_formats * sizeof(XvImageFormatValues)); + ret = Xcalloc(rep.num_formats, sizeof(XvImageFormatValues)); if (ret != NULL) { for (unsigned int i = 0; i < rep.num_formats; i++) { -- cgit v1.2.3