summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatt Turner <[email protected]>2012-09-04 23:09:22 -0700
committerMatt Turner <[email protected]>2012-09-05 22:28:50 -0700
commit6bda027e01c15df24d36de5bf3838ea8ed7e9e56 (patch)
treebb41d06abd676913add0761732908c064b68663a /src
parent5067506ea6ada5eeae33b1acf1c916e00121c12a (diff)
Use calloc instead of malloc/memset-0
This patch has been generated by the following Coccinelle semantic patch: @@ expression E; identifier I; @@ - I = malloc(E); + I = calloc(1, E); ... - memset(I, 0, sizeof *I); Reviewed-by: Brian Paul <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/egl/drivers/dri2/egl_dri2.c4
-rw-r--r--src/egl/drivers/dri2/platform_drm.c7
-rw-r--r--src/egl/drivers/dri2/platform_wayland.c4
-rw-r--r--src/egl/drivers/dri2/platform_x11.c8
-rw-r--r--src/glx/applegl_glx.c3
-rw-r--r--src/glx/dri2_glx.c12
-rw-r--r--src/glx/dri_glx.c6
-rw-r--r--src/glx/drisw_glx.c9
-rw-r--r--src/glx/indirect_glx.c6
9 files changed, 18 insertions, 41 deletions
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index f99bcad3081..4b58c35b46b 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1477,12 +1477,10 @@ _eglBuiltInDriverDRI2(const char *args)
(void) args;
- dri2_drv = malloc(sizeof *dri2_drv);
+ dri2_drv = calloc(1, sizeof *dri2_drv);
if (!dri2_drv)
return NULL;
- memset(dri2_drv, 0, sizeof *dri2_drv);
-
if (!dri2_load(&dri2_drv->base)) {
free(dri2_drv);
return NULL;
diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c
index 9aafb525b93..3e04a6cdcb0 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -96,13 +96,12 @@ dri2_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
(void) drv;
- dri2_surf = malloc(sizeof *dri2_surf);
+ dri2_surf = calloc(1, sizeof *dri2_surf);
if (!dri2_surf) {
_eglError(EGL_BAD_ALLOC, "dri2_create_surface");
return NULL;
}
- memset(dri2_surf, 0, sizeof *dri2_surf);
if (!_eglInitSurface(&dri2_surf->base, disp, type, conf, attrib_list))
goto cleanup_surf;
@@ -399,12 +398,10 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
int fd = -1;
int i;
- dri2_dpy = malloc(sizeof *dri2_dpy);
+ dri2_dpy = calloc(1, sizeof *dri2_dpy);
if (!dri2_dpy)
return _eglError(EGL_BAD_ALLOC, "eglInitialize");
- memset(dri2_dpy, 0, sizeof *dri2_dpy);
-
disp->DriverData = (void *) dri2_dpy;
gbm = disp->PlatformDisplay;
diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c
index d291f0ffa40..d9b45f1cec2 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -813,12 +813,10 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp)
drv->API.CreateImageKHR = dri2_wayland_create_image_khr;
drv->API.Terminate = dri2_terminate;
- dri2_dpy = malloc(sizeof *dri2_dpy);
+ dri2_dpy = calloc(1, sizeof *dri2_dpy);
if (!dri2_dpy)
return _eglError(EGL_BAD_ALLOC, "eglInitialize");
- memset(dri2_dpy, 0, sizeof *dri2_dpy);
-
disp->DriverData = (void *) dri2_dpy;
if (disp->PlatformDisplay == NULL) {
dri2_dpy->wl_dpy = wl_display_connect(NULL);
diff --git a/src/egl/drivers/dri2/platform_x11.c b/src/egl/drivers/dri2/platform_x11.c
index f7dc89dc992..25337741437 100644
--- a/src/egl/drivers/dri2/platform_x11.c
+++ b/src/egl/drivers/dri2/platform_x11.c
@@ -980,12 +980,10 @@ dri2_initialize_x11_swrast(_EGLDriver *drv, _EGLDisplay *disp)
drv->API.CreateDRMImageMESA = NULL;
drv->API.ExportDRMImageMESA = NULL;
- dri2_dpy = malloc(sizeof *dri2_dpy);
+ dri2_dpy = calloc(1, sizeof *dri2_dpy);
if (!dri2_dpy)
return _eglError(EGL_BAD_ALLOC, "eglInitialize");
- memset(dri2_dpy, 0, sizeof *dri2_dpy);
-
disp->DriverData = (void *) dri2_dpy;
if (disp->PlatformDisplay == NULL) {
dri2_dpy->conn = xcb_connect(0, 0);
@@ -1056,12 +1054,10 @@ dri2_initialize_x11_dri2(_EGLDriver *drv, _EGLDisplay *disp)
drv->API.PostSubBufferNV = dri2_post_sub_buffer;
drv->API.SwapInterval = dri2_swap_interval;
- dri2_dpy = malloc(sizeof *dri2_dpy);
+ dri2_dpy = calloc(1, sizeof *dri2_dpy);
if (!dri2_dpy)
return _eglError(EGL_BAD_ALLOC, "eglInitialize");
- memset(dri2_dpy, 0, sizeof *dri2_dpy);
-
disp->DriverData = (void *) dri2_dpy;
if (disp->PlatformDisplay == NULL) {
dri2_dpy->conn = xcb_connect(0, 0);
diff --git a/src/glx/applegl_glx.c b/src/glx/applegl_glx.c
index c3597cee765..a67416ec3f4 100644
--- a/src/glx/applegl_glx.c
+++ b/src/glx/applegl_glx.c
@@ -173,11 +173,10 @@ applegl_create_screen(int screen, struct glx_display * priv)
{
struct glx_screen *psc;
- psc = malloc(sizeof *psc);
+ psc = calloc(1, sizeof *psc);
if (psc == NULL)
return NULL;
- memset(psc, 0, sizeof *psc);
glx_screen_init(psc, screen, priv);
psc->vtable = &applegl_screen_vtable;
diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c
index 5644f665c4c..f2fc1873298 100644
--- a/src/glx/dri2_glx.c
+++ b/src/glx/dri2_glx.c
@@ -198,11 +198,10 @@ dri2_create_context(struct glx_screen *base,
shared = pcp_shared->driContext;
}
- pcp = malloc(sizeof *pcp);
+ pcp = calloc(1, sizeof *pcp);
if (pcp == NULL)
return NULL;
- memset(pcp, 0, sizeof *pcp);
if (!glx_context_init(&pcp->base, &psc->base, &config->base)) {
free(pcp);
return NULL;
@@ -261,13 +260,12 @@ dri2_create_context_attribs(struct glx_screen *base,
shared = pcp_shared->driContext;
}
- pcp = malloc(sizeof *pcp);
+ pcp = calloc(1, sizeof *pcp);
if (pcp == NULL) {
*error = __DRI_CTX_ERROR_NO_MEMORY;
goto error_exit;
}
- memset(pcp, 0, sizeof *pcp);
if (!glx_context_init(&pcp->base, &psc->base, &config->base))
goto error_exit;
@@ -352,11 +350,10 @@ dri2CreateDrawable(struct glx_screen *base, XID xDrawable,
struct dri2_display *pdp;
GLint vblank_mode = DRI_CONF_VBLANK_DEF_INTERVAL_1;
- pdraw = malloc(sizeof(*pdraw));
+ pdraw = calloc(1, sizeof(*pdraw));
if (!pdraw)
return NULL;
- memset(pdraw, 0, sizeof *pdraw);
pdraw->base.destroyDrawable = dri2DestroyDrawable;
pdraw->base.xDrawable = xDrawable;
pdraw->base.drawable = drawable;
@@ -1018,11 +1015,10 @@ dri2CreateScreen(int screen, struct glx_display * priv)
drm_magic_t magic;
int i;
- psc = malloc(sizeof *psc);
+ psc = calloc(1, sizeof *psc);
if (psc == NULL)
return NULL;
- memset(psc, 0, sizeof *psc);
psc->fd = -1;
if (!glx_screen_init(&psc->base, screen, priv)) {
diff --git a/src/glx/dri_glx.c b/src/glx/dri_glx.c
index a158de023ba..3a727e52904 100644
--- a/src/glx/dri_glx.c
+++ b/src/glx/dri_glx.c
@@ -593,11 +593,10 @@ dri_create_context(struct glx_screen *base,
shared = pcp_shared->driContext;
}
- pcp = malloc(sizeof *pcp);
+ pcp = calloc(1, sizeof *pcp);
if (pcp == NULL)
return NULL;
- memset(pcp, 0, sizeof *pcp);
if (!glx_context_init(&pcp->base, &psc->base, &config->base)) {
free(pcp);
return NULL;
@@ -651,11 +650,10 @@ driCreateDrawable(struct glx_screen *base,
if (xDrawable != drawable)
return NULL;
- pdp = malloc(sizeof *pdp);
+ pdp = calloc(1, sizeof *pdp);
if (!pdp)
return NULL;
- memset(pdp, 0, sizeof *pdp);
pdp->base.drawable = drawable;
pdp->base.psc = &psc->base;
diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c
index b68e62272c7..920a9ab7b99 100644
--- a/src/glx/drisw_glx.c
+++ b/src/glx/drisw_glx.c
@@ -392,11 +392,10 @@ drisw_create_context(struct glx_screen *base,
shared = pcp_shared->driContext;
}
- pcp = malloc(sizeof *pcp);
+ pcp = calloc(1, sizeof *pcp);
if (pcp == NULL)
return NULL;
- memset(pcp, 0, sizeof *pcp);
if (!glx_context_init(&pcp->base, &psc->base, &config->base)) {
free(pcp);
return NULL;
@@ -457,11 +456,10 @@ drisw_create_context_attribs(struct glx_screen *base,
shared = pcp_shared->driContext;
}
- pcp = malloc(sizeof *pcp);
+ pcp = calloc(1, sizeof *pcp);
if (pcp == NULL)
return NULL;
- memset(pcp, 0, sizeof *pcp);
if (!glx_context_init(&pcp->base, &psc->base, &config->base)) {
free(pcp);
return NULL;
@@ -522,11 +520,10 @@ driswCreateDrawable(struct glx_screen *base, XID xDrawable,
Bool ret;
const __DRIswrastExtension *swrast = psc->swrast;
- pdp = malloc(sizeof(*pdp));
+ pdp = calloc(1, sizeof(*pdp));
if (!pdp)
return NULL;
- memset(pdp, 0, sizeof *pdp);
pdp->base.xDrawable = xDrawable;
pdp->base.drawable = drawable;
pdp->base.psc = &psc->base;
diff --git a/src/glx/indirect_glx.c b/src/glx/indirect_glx.c
index 5eef59c1d5a..f3cc1e7d049 100644
--- a/src/glx/indirect_glx.c
+++ b/src/glx/indirect_glx.c
@@ -352,12 +352,11 @@ indirect_create_context(struct glx_screen *psc,
}
/* Allocate our context record */
- gc = malloc(sizeof *gc);
+ gc = calloc(1, sizeof *gc);
if (!gc) {
/* Out of memory */
return NULL;
}
- memset(gc, 0, sizeof *gc);
glx_context_init(gc, psc, mode);
gc->isDirect = GL_FALSE;
@@ -464,11 +463,10 @@ indirect_create_screen(int screen, struct glx_display * priv)
{
struct glx_screen *psc;
- psc = malloc(sizeof *psc);
+ psc = calloc(1, sizeof *psc);
if (psc == NULL)
return NULL;
- memset(psc, 0, sizeof *psc);
glx_screen_init(psc, screen, priv);
psc->vtable = &indirect_screen_vtable;