]> granicus.if.org Git - flex/commitdiff
scanner: use calloc to allocate new filter memory
authorMichael W. Bombardieri <mb@ii.net>
Wed, 29 Nov 2017 13:11:22 +0000 (08:11 -0500)
committerWill Estes <westes575@gmail.com>
Wed, 29 Nov 2017 13:11:22 +0000 (08:11 -0500)
src/filter.c

index ccdcdd631c99867e7a4366316af5f598570c06ed..a7e69ec2aa9f40f1359e7fed6d1c7e4d82337370 100644 (file)
@@ -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;