From: millert Date: Wed, 8 Jan 2014 22:36:37 +0000 (+0000) Subject: Use calloc() instead of malloc() + memset. Based on a diff from X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=f6169c9ed6db5ac49873a82567414e6c3146a655;p=openbsd Use calloc() instead of malloc() + memset. Based on a diff from Michael W. Bombardieri. OK deraadt@ --- diff --git a/usr.bin/yacc/lr0.c b/usr.bin/yacc/lr0.c index 10e4b2146c4..6ac2e91998e 100644 --- a/usr.bin/yacc/lr0.c +++ b/usr.bin/yacc/lr0.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lr0.c,v 1.14 2014/01/08 22:30:32 millert Exp $ */ +/* $OpenBSD: lr0.c,v 1.15 2014/01/08 22:36:37 millert Exp $ */ /* $NetBSD: lr0.c,v 1.4 1996/03/19 03:21:35 jtc Exp $ */ /* @@ -510,11 +510,9 @@ set_nullable(void) int empty; int done; - nullable = malloc(nsyms); + nullable = calloc(1, nsyms); if (nullable == 0) no_space(); - memset(nullable, 0, nsyms); - done = 0; while (!done) { diff --git a/usr.bin/yacc/output.c b/usr.bin/yacc/output.c index 520ef546461..dd00477248f 100644 --- a/usr.bin/yacc/output.c +++ b/usr.bin/yacc/output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: output.c,v 1.17 2014/01/08 21:40:25 millert Exp $ */ +/* $OpenBSD: output.c,v 1.18 2014/01/08 22:36:37 millert Exp $ */ /* $NetBSD: output.c,v 1.4 1996/03/19 03:21:41 jtc Exp $ */ /* @@ -996,12 +996,9 @@ output_debug(void) ++outline; fprintf(code_file, "#define YYMAXTOKEN %d\n", max); - symnam = (char **) malloc((max+1)*sizeof(char *)); + symnam = (char **) calloc(max+1, sizeof(char *)); if (symnam == 0) no_space(); - /* Note that it is not necessary to initialize the element */ - /* symnam[max]. */ - memset(symnam, 0, max * sizeof(char *)); for (i = ntokens - 1; i >= 2; --i) symnam[symbol_value[i]] = symbol_name[i]; symnam[0] = "end-of-file";