[PATCH 3/5] clients: Use calloc instead of malloc/memset=0

Kristian Høgsberg hoegsberg at gmail.com
Fri May 9 12:37:38 PDT 2014


On Wed, May 07, 2014 at 02:13:11AM +0000, Bryce W. Harrington wrote:
> 
> Signed-off-by: Bryce Harrington <b.harrington at samsung.com>
> ---
>  clients/editor.c      |    4 +---
>  clients/subsurfaces.c |    8 ++------
>  clients/window.c      |   13 ++-----------
>  3 files changed, 5 insertions(+), 20 deletions(-)
> 
> diff --git a/clients/editor.c b/clients/editor.c
> index 6ed76d4..b439d9e 100644
> --- a/clients/editor.c
> +++ b/clients/editor.c
> @@ -559,9 +559,7 @@ text_entry_create(struct editor *editor, const char *text)
>  {
>  	struct text_entry *entry;
>  
> -	entry = xmalloc(sizeof *entry);
> -	memset(entry, 0, sizeof *entry);
> -
> +	entry = xcalloc(1, sizeof *entry);

We have zalloc for when we just want malloc+memset.

Kristian

>  	entry->widget = widget_add_widget(editor->widget, entry);
>  	entry->window = editor->window;
>  	entry->text = strdup(text);
> diff --git a/clients/subsurfaces.c b/clients/subsurfaces.c
> index 15af9aa..a683787 100644
> --- a/clients/subsurfaces.c
> +++ b/clients/subsurfaces.c
> @@ -492,9 +492,7 @@ triangle_create(struct window *window, struct egl_state *egl)
>  {
>  	struct triangle *tri;
>  
> -	tri = xmalloc(sizeof *tri);
> -	memset(tri, 0, sizeof *tri);
> -
> +	tri = xcalloc(1, sizeof *tri);
>  	tri->egl = egl;
>  	tri->widget = window_add_subsurface(window, tri,
>  		int_to_mode(option_triangle_mode));
> @@ -714,9 +712,7 @@ demoapp_create(struct display *display)
>  {
>  	struct demoapp *app;
>  
> -	app = xmalloc(sizeof *app);
> -	memset(app, 0, sizeof *app);
> -
> +	app = xcalloc(1, sizeof *app);
>  	app->egl = egl_state_create(display_get_display(display));
>  
>  	app->display = display;
> diff --git a/clients/window.c b/clients/window.c
> index cfc1260..2212351 100644
> --- a/clients/window.c
> +++ b/clients/window.c
> @@ -1139,12 +1139,7 @@ shm_surface_create(struct display *display, struct wl_surface *wl_surface,
>  	struct shm_surface *surface;
>  	DBG_OBJ(wl_surface, "\n");
>  
> -	surface = xmalloc(sizeof *surface);
> -	memset(surface, 0, sizeof *surface);
> -
> -	if (!surface)
> -		return NULL;
> -
> +	surface = xcalloc(1, sizeof *surface);
>  	surface->base.prepare = shm_surface_prepare;
>  	surface->base.swap = shm_surface_swap;
>  	surface->base.acquire = shm_surface_acquire;
> @@ -4336,11 +4331,7 @@ surface_create(struct window *window)
>  	struct display *display = window->display;
>  	struct surface *surface;
>  
> -	surface = xmalloc(sizeof *surface);
> -	memset(surface, 0, sizeof *surface);
> -	if (!surface)
> -		return NULL;
> -
> +	surface = xcalloc(1, sizeof *surface);
>  	surface->window = window;
>  	surface->surface = wl_compositor_create_surface(display->compositor);
>  	surface->buffer_scale = 1;
> -- 
> 1.7.9.5
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list