diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2024-07-21 11:10:44 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2024-07-21 11:57:47 -0700 |
commit | dd8c77a0c0d62ab88cf96ac507562469a7bcbc5a (patch) | |
tree | 2c8d19595f9ad23acda222d96c83309f3b720842 /src | |
parent | b022c9cf7004fe6f794c4c00dd519a2e4c74eca0 (diff) |
Use calloc instead of malloc and manual loops to zero array contents
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libxv/-/merge_requests/7>
Diffstat (limited to 'src')
-rw-r--r-- | src/Xv.c | 26 |
1 files changed, 4 insertions, 22 deletions
@@ -204,8 +204,7 @@ 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; } @@ -214,14 +213,6 @@ XvQueryAdaptors( 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; if (u.buffer + sz_xvAdaptorInfo > end) { @@ -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,8 +369,7 @@ 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; } @@ -389,13 +378,6 @@ XvQueryEncodings( 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; if (u.buffer + sz_xvEncodingInfo > end) { @@ -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++) { |