[PATCH weston] tests: Convert 'xalloc's to 'zalloc's

Seedo Eldho Paul seedoeldhopaul at gmail.com
Fri Sep 4 20:13:15 PDT 2015


On Sep 5, 2015 5:13 AM, "Peter Hutterer" <peter.hutterer at who-t.net> wrote:
>
> On Fri, Sep 04, 2015 at 11:47:09PM +0530, Seedo Eldho Paul wrote:
> > xalloc terminates the program abruptly if the requested amount of
> > memory couldn't be allocated. To insure that the errors are handled
> > cleanly, use zalloc instead.
> >
> > Signed-off-by: Seedo Eldho Paul <seedoeldhopaul at gmail.com>
> > ---
> >  tests/internal-screenshot-test.c | 11 ++++++-----
>
> do you really care about correct OOM handling in a test?

Hi Peter,

Initially I posted a patch to remove the dead code if xzalloc is used:
http://lists.freedesktop.org/archives/wayland-devel/2015-September/024151.html.
Then Bryce wanted me to do it in this way instead.

SEEDO

>
> Cheers,
>    Peter
>
> >  1 file changed, 6 insertions(+), 5 deletions(-)
> >
> > diff --git a/tests/internal-screenshot-test.c
b/tests/internal-screenshot-test.c
> > index e72a695..6b26e1a 100644
> > --- a/tests/internal-screenshot-test.c
> > +++ b/tests/internal-screenshot-test.c
> > @@ -30,6 +30,7 @@
> >  #include <string.h> /* memcpy */
> >  #include <cairo.h>
> >
> > +#include "zalloc.h"
> >  #include "weston-test-client-helper.h"
> >
> >  char *server_parameters="--use-pixman --width=320 --height=240";
> > @@ -92,9 +93,9 @@ load_surface_from_png(const char *fname)
> >       }
> >
> >       /* Disguise the cairo surface in a weston test surface */
> > -     reference = xzalloc(sizeof *reference);
> > +     reference = zalloc(sizeof *reference);
> >       if (reference == NULL) {
> > -             perror("xzalloc reference");
> > +             perror("zalloc reference");
> >               cairo_surface_destroy(reference_cairo_surface);
> >               return NULL;
> >       }
> > @@ -114,9 +115,9 @@ load_surface_from_png(const char *fname)
> >
> >       /* Allocate new buffer for our weston reference, and copy the
data from
> >          the cairo surface so we can destroy it */
> > -     reference->data = xzalloc(source_data_size);
> > +     reference->data = zalloc(source_data_size);
> >       if (reference->data == NULL) {
> > -             perror("xzalloc reference data");
> > +             perror("zalloc reference data");
> >               cairo_surface_destroy(reference_cairo_surface);
> >               free(reference);
> >               return NULL;
> > @@ -143,7 +144,7 @@ static struct surface*
> >  create_screenshot_surface(struct client *client)
> >  {
> >       struct surface* screenshot;
> > -     screenshot = xzalloc(sizeof *screenshot);
> > +     screenshot = zalloc(sizeof *screenshot);
> >       if (screenshot == NULL)
> >               return NULL;
> >       screenshot->wl_buffer = create_shm_buffer(client,
> > --
> > 1.9.1
> >
> > _______________________________________________
> > wayland-devel mailing list
> > wayland-devel at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/wayland-devel
> >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20150904/53c7e004/attachment.html>


More information about the wayland-devel mailing list