[PATCH] wayland-client: Initialize newly created wl_proxys to zero.
Marek Chalupa
mchqwerty at gmail.com
Tue Aug 12 00:27:02 PDT 2014
On 11 August 2014 18:02, Nils Chr. Brause <nilschrbrause at gmail.com> wrote:
> On Mon, Aug 11, 2014 at 08:36:51AM +0200, Marek Chalupa wrote:
> > > proxy->flags = 0;
> > >
> >
> > After memset, this line can be removed as well.
> >
> >
> > > @@ -331,10 +331,10 @@ wl_proxy_create_for_id(struct wl_proxy *factory,
> > > if (proxy == NULL)
> > > return NULL;
> > >
> > > + memset(proxy, 0, sizeof *proxy);
> > > +
> > > proxy->object.interface = interface;
> > > - proxy->object.implementation = NULL;
> > > proxy->object.id = id;
> > > - proxy->dispatcher = NULL;
> > > proxy->display = display;
> > > proxy->queue = factory->queue;
> > > proxy->flags = 0;
> > >
> >
> > The same.
> >
>
> Yes, of course. I guess we can also remove similar lines from
> wl_display_connect_to_fd then?
I think this should be in a separate patch, but let's see what say the
others.
> New patch including this:
>
>
> From ec5eff0720efd90e868711a9b58bf1a435d156ce Mon Sep 17 00:00:00 2001
> From: "Nils Chr. Brause" <nilschrbrause at googlemail.com>
> Date: Fri, 8 Aug 2014 18:06:16 +0200
> Subject: [PATCH] wayland-client: Initialize newly created wl_proxys to
> zero.
>
> Up until now, newly created wl_proxys (with proxy_create or
> wl_proxy_create_for_id) are not initialized properly after memory
> allocation. The wl_display object in contrast is. To prevent giving
> uninitialized data to the user (e.g. user_data) an appropriate memset
> has been added. Also, after a memset members don't have to be
> explicitly initialized with zero anymore.
>
> Signed-off-by: Nils Chr. Brause <nilschrbrause at googlemail.com>
> ---
> src/wayland-client.c | 12 ++++--------
> 1 file changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/src/wayland-client.c b/src/wayland-client.c
> index 3e401d3..8054999 100644
> --- a/src/wayland-client.c
> +++ b/src/wayland-client.c
> @@ -274,12 +274,11 @@ proxy_create(struct wl_proxy *factory, const struct
> wl_interface *interface)
> if (proxy == NULL)
> return NULL;
>
> + memset(proxy, 0, sizeof *proxy);
> +
> proxy->object.interface = interface;
> - proxy->object.implementation = NULL;
> - proxy->dispatcher = NULL;
> proxy->display = display;
> proxy->queue = factory->queue;
> - proxy->flags = 0;
> proxy->refcount = 1;
>
> proxy->object.id = wl_map_insert_new(&display->objects, 0, proxy);
> @@ -331,13 +330,12 @@ wl_proxy_create_for_id(struct wl_proxy *factory,
> if (proxy == NULL)
> return NULL;
>
> + memset(proxy, 0, sizeof *proxy);
> +
> proxy->object.interface = interface;
> - proxy->object.implementation = NULL;
> proxy->object.id = id;
> - proxy->dispatcher = NULL;
> proxy->display = display;
> proxy->queue = factory->queue;
> - proxy->flags = 0;
> proxy->refcount = 1;
>
> wl_map_insert_at(&display->objects, 0, id, proxy);
> @@ -771,7 +769,6 @@ wl_display_connect_to_fd(int fd)
> wl_list_init(&display->event_queue_list);
> pthread_mutex_init(&display->mutex, NULL);
> pthread_cond_init(&display->reader_cond, NULL);
> - display->reader_count = 0;
>
> wl_map_insert_new(&display->objects, 0, NULL);
>
> @@ -782,7 +779,6 @@ wl_display_connect_to_fd(int fd)
> display->proxy.object.implementation = (void(**)(void))
> &display_listener;
> display->proxy.user_data = display;
> display->proxy.queue = &display->default_queue;
> - display->proxy.flags = 0;
> display->proxy.refcount = 1;
>
> display->connection = wl_connection_create(display->fd);
> --
> 2.0.4
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20140812/44a0403e/attachment-0001.html>
More information about the wayland-devel
mailing list