Re: [Flex-devel] filter.c: malloc+memset -> calloc
flex is a tool for generating scanners
Brought to you by:
wlestes
From: Will E. <wes...@gm...> - 2017-11-29 13:12:13
|
Thanks. This is on master and will be included in the next release of flex. On Monday, 4 September 2017, 2:06 pm +0800, "Michael W. Bombardieri" <mb...@ii...> wrote: > Hello, > > In flex's filter.c two instances of memset() can be removed if calloc() > is used for allocating the buffer. This was recently committed into > OpenBSD's version of flex here: > http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/lex/filter.c.diff?r1=1.7&r2=1.8&f=h > > Have a nice day. > > - Michael > > > diff --git a/src/filter.c b/src/filter.c > index ccdcdd6..a7e69ec 100644 > --- a/src/filter.c > +++ b/src/filter.c > @@ -47,10 +47,9 @@ struct filter *filter_create_ext (struct filter *chain, const char *cmd, > va_list ap; > > /* allocate and initialize new filter */ > - f = malloc(sizeof(struct filter)); > + f = calloc(sizeof(struct filter), 1); > if (!f) > - flexerror(_("malloc failed (f) in filter_create_ext")); > - memset (f, 0, sizeof (*f)); > + flexerror(_("calloc failed (f) in filter_create_ext")); > f->filter_func = NULL; > f->extra = NULL; > f->next = NULL; > @@ -100,10 +99,9 @@ struct filter *filter_create_int (struct filter *chain, > struct filter *f; > > /* allocate and initialize new filter */ > - f = malloc(sizeof(struct filter)); > + f = calloc(sizeof(struct filter), 1); > if (!f) > - flexerror(_("malloc failed in filter_create_int")); > - memset (f, 0, sizeof (*f)); > + flexerror(_("calloc failed in filter_create_int")); > f->next = NULL; > f->argc = 0; > f->argv = NULL; > > ------------------------------------------------------------------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > Flex-devel mailing list > Fle...@li... > https://lists.sourceforge.net/lists/listinfo/flex-devel -- Will Estes wes...@gm... |