[PATCH v2 16/17] Convert hw/kdrive to new *allocarray functions
Alan Coopersmith
alan.coopersmith at oracle.com
Thu Apr 16 18:49:24 PDT 2015
Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
Reviewed-by: Matt Turner <mattst88 at gmail.com>
---
hw/kdrive/ephyr/ephyrdriext.c | 4 ++--
hw/kdrive/ephyr/hostx.c | 14 +++++++-------
hw/kdrive/fake/fake.c | 2 +-
hw/kdrive/fbdev/fbdev.c | 2 +-
hw/kdrive/src/kshadow.c | 2 +-
hw/kdrive/src/kxv.c | 4 ++--
6 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/hw/kdrive/ephyr/ephyrdriext.c b/hw/kdrive/ephyr/ephyrdriext.c
index 3d5cf77..748b608 100644
--- a/hw/kdrive/ephyr/ephyrdriext.c
+++ b/hw/kdrive/ephyr/ephyrdriext.c
@@ -431,8 +431,8 @@ EphyrDuplicateVisual(unsigned int a_screen,
* extend the list of visual IDs in that entry,
* so to add a_new_id in there.
*/
- vids = realloc(cur_depth->vids,
- (cur_depth->numVids + 1) * sizeof(VisualID));
+ vids = reallocarray(cur_depth->vids,
+ cur_depth->numVids + 1, sizeof(VisualID));
if (!vids) {
EPHYR_LOG_ERROR("failed to realloc numids\n");
goto out;
diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index c67ff60..7163af0 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -129,8 +129,8 @@ hostx_add_screen(KdScreenInfo *screen, unsigned long win_id, int screen_num, Boo
int index = HostX.n_screens;
HostX.n_screens += 1;
- HostX.screens = realloc(HostX.screens,
- HostX.n_screens * sizeof(HostX.screens[0]));
+ HostX.screens = reallocarray(HostX.screens,
+ HostX.n_screens, sizeof(HostX.screens[0]));
HostX.screens[index] = screen;
scrpriv->screen = screen;
@@ -867,7 +867,7 @@ hostx_screen_init(KdScreenInfo *screen,
NULL);
scrpriv->ximg->data =
- malloc(scrpriv->ximg->stride * buffer_height);
+ xallocarray(scrpriv->ximg->stride, buffer_height);
}
{
@@ -933,7 +933,7 @@ hostx_screen_init(KdScreenInfo *screen,
*bits_per_pixel = scrpriv->server_depth;
EPHYR_DBG("server bpp %i", bytes_per_pixel);
- scrpriv->fb_data = malloc (stride * buffer_height);
+ scrpriv->fb_data = xallocarray (stride, buffer_height);
return scrpriv->fb_data;
}
}
@@ -1148,9 +1148,9 @@ hostx_get_visuals_info(EphyrHostVisualInfo ** a_visuals, int *a_num_entries)
for (; depths.rem; xcb_depth_next(&depths)) {
xcb_visualtype_t *visuals = xcb_depth_visuals(depths.data);
EphyrHostVisualInfo *tmp_visuals =
- realloc(host_visuals,
- (nb_items + depths.data->visuals_len)
- * sizeof(EphyrHostVisualInfo));
+ reallocarray(host_visuals,
+ nb_items + depths.data->visuals_len,
+ sizeof(EphyrHostVisualInfo));
if (!tmp_visuals) {
goto out;
}
diff --git a/hw/kdrive/fake/fake.c b/hw/kdrive/fake/fake.c
index 90e3ec9..04a7278 100644
--- a/hw/kdrive/fake/fake.c
+++ b/hw/kdrive/fake/fake.c
@@ -158,7 +158,7 @@ fakeMapFramebuffer(KdScreenInfo * screen)
priv->bytes_per_line =
((screen->width * screen->fb.bitsPerPixel + 31) >> 5) << 2;
free(priv->base);
- priv->base = malloc(priv->bytes_per_line * screen->height);
+ priv->base = xallocarray(priv->bytes_per_line, screen->height);
if (scrpriv->shadow) {
if (!KdShadowFbAlloc
diff --git a/hw/kdrive/fbdev/fbdev.c b/hw/kdrive/fbdev/fbdev.c
index 95f64cb..23f7509 100644
--- a/hw/kdrive/fbdev/fbdev.c
+++ b/hw/kdrive/fbdev/fbdev.c
@@ -677,7 +677,7 @@ fbdevCreateColormap(ColormapPtr pmap)
case FB_VISUAL_STATIC_PSEUDOCOLOR:
pVisual = pmap->pVisual;
nent = pVisual->ColormapEntries;
- pdefs = malloc(nent * sizeof(xColorItem));
+ pdefs = xallocarray(nent, sizeof(xColorItem));
if (!pdefs)
return FALSE;
for (i = 0; i < nent; i++)
diff --git a/hw/kdrive/src/kshadow.c b/hw/kdrive/src/kshadow.c
index 828ea19..7f1e2ee 100644
--- a/hw/kdrive/src/kshadow.c
+++ b/hw/kdrive/src/kshadow.c
@@ -36,7 +36,7 @@ KdShadowFbAlloc(KdScreenInfo * screen, Bool rotate)
/* use fb computation for width */
paddedWidth = ((width * bpp + FB_MASK) >> FB_SHIFT) * sizeof(FbBits);
- buf = malloc(paddedWidth * height);
+ buf = xallocarray(paddedWidth, height);
if (!buf)
return FALSE;
if (screen->fb.shadow)
diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c
index 369db33..844deca 100644
--- a/hw/kdrive/src/kxv.c
+++ b/hw/kdrive/src/kxv.c
@@ -327,8 +327,8 @@ KdXVInitAdaptors(ScreenPtr pScreen, KdVideoAdaptorPtr infoPtr, int number)
void *moreSpace;
totFormat *= 2;
- moreSpace = realloc(pFormat,
- totFormat * sizeof(XvFormatRec));
+ moreSpace = reallocarray(pFormat, totFormat,
+ sizeof(XvFormatRec));
if (!moreSpace)
break;
pFormat = moreSpace;
--
1.7.9.2
More information about the xorg-devel
mailing list