summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2024-07-21 11:10:44 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2024-07-21 11:57:47 -0700
commitdd8c77a0c0d62ab88cf96ac507562469a7bcbc5a (patch)
tree2c8d19595f9ad23acda222d96c83309f3b720842
parentb022c9cf7004fe6f794c4c00dd519a2e4c74eca0 (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>
-rw-r--r--src/Xv.c26
1 files changed, 4 insertions, 22 deletions
diff --git a/src/Xv.c b/src/Xv.c
index 5bb0589..2a7e6c5 100644
--- a/src/Xv.c
+++ b/src/Xv.c
@@ -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++) {