[systemd-devel] [PATCH 3/3] bootchart: Convert malloc/memset to calloc.
Lennart Poettering
lennart at poettering.net
Tue Jan 15 19:30:00 PST 2013
On Wed, 16.01.13 00:17, Jan Engelhardt (jengelh at inai.de) wrote:
> On Tuesday 2013-01-15 20:47, Lennart Poettering wrote:
> >> --- a/src/bootchart/bootchart.c
> >> +++ b/src/bootchart/bootchart.c
> >> @@ -232,12 +232,11 @@ int main(int argc, char *argv[])
> >> }
> >>
> >> /* start with empty ps LL */
> >> - ps_first = malloc(sizeof(struct ps_struct));
> >> + ps_first = calloc(1, sizeof(struct ps_struct));
> >
> >BTW, we have a nice macro for this:
> >
> > ps_first = new0(struct ps_struct, 1);
> >
> >It's tape-safe and a bit nicer to read.
>
> If tape-safety was that important, one would do away with tapes
> altogether and use sizeof with like ps_first = calloc(1, sizeof(*ps_first))
Well, that would infer the type from the variable. The new0() code above
otoh includes the extra sanity check that the variable we assign the
object we allocate to is actually of the right type to accept the object
we are allocating.
Lennart
--
Lennart Poettering - Red Hat, Inc.
More information about the systemd-devel
mailing list