[PATCH 1/2] clients & tests: Unify multiple definitions of x*alloc and related functions

Bryce Harrington bryce at osg.samsung.com
Wed Mar 16 20:49:30 UTC 2016


On Wed, Mar 16, 2016 at 11:49:40AM -0700, Bill Spitzak wrote:
> On Tue, Mar 15, 2016 at 3:23 PM, Bryce Harrington <bryce at osg.samsung.com>
> wrote:
> 
> >
> > --- a/clients/ivi-shell-user-interface.c
> > +++ b/clients/ivi-shell-user-interface.c
> > @@ -40,6 +40,7 @@
> >  #include "shared/config-parser.h"
> >  #include "shared/helpers.h"
> >  #include "shared/os-compatibility.h"
> > +#include "shared/xalloc.h"
> >  #include "shared/zalloc.h"
> >  #include "ivi-application-client-protocol.h"
> >  #include "ivi-hmi-controller-client-protocol.h"
> > @@ -164,18 +165,6 @@ hmi_homescreen_setting {
> >  };
> >
> >  static void *
> > -fail_on_null(void *p, size_t size, char *file, int32_t line)
> > -{
> > -       if (size && !p) {
> > -               fprintf(stderr, "%s(%d) %zd: out of memory\n",
> > -                       file, line, size);
> > -               exit(EXIT_FAILURE);
> > -       }
> > -
> > -       return p;
> > -}
> >
> 
> The deleted ones in ivi purposely does not fail if size==0. But it appears
> they are only called by the MEM_ALLOC macro and that is only called with
> sizeof() which is not going to be zero, so this is ok.
> 
> >
> > -               fail_on_null(window->xdg_surface);
> > +               fail_on_null(window->xdg_surface, 1, __FILE__, __LINE__);
> >
> 
> I think you either want to use sizeof(*window->xdg_surface) or 0 for the
> size.

Probably 0 then; in this ivi code fail_on_null() is principally being
used to check for a null pointer, so the size of the struct may not be
as relevant in this context.

Thanks for the review, I'll update all instances like this.

Bryce


More information about the wayland-devel mailing list