From 07d3058c2b8ee0e092c9cce25e035c6571288f3e Mon Sep 17 00:00:00 2001 From: millert Date: Wed, 8 Jan 2014 22:30:32 +0000 Subject: [PATCH] Make allocate() take size_t and return void *. This lets us drop some more useless casts. Also add missing arguments to a couple of prototypes while here. OK matthew@ pelikan@ --- usr.bin/yacc/defs.h | 12 ++++++------ usr.bin/yacc/lr0.c | 10 ++++------ usr.bin/yacc/main.c | 16 ++++++++-------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/usr.bin/yacc/defs.h b/usr.bin/yacc/defs.h index 02de7b5b7b0..1aa9f3d8e02 100644 --- a/usr.bin/yacc/defs.h +++ b/usr.bin/yacc/defs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: defs.h,v 1.13 2014/01/08 21:40:25 millert Exp $ */ +/* $OpenBSD: defs.h,v 1.14 2014/01/08 22:30:32 millert Exp $ */ /* $NetBSD: defs.h,v 1.6 1996/03/19 03:21:30 jtc Exp $ */ /* @@ -137,8 +137,8 @@ /* storage allocation macros */ -#define NEW(t) ((t*)allocate(sizeof(t))) -#define NEW2(n,t) ((t*)allocate((unsigned)((n)*sizeof(t)))) +#define NEW(t) (allocate(sizeof(t))) +#define NEW2(n,t) (allocate((n)*sizeof(t))) /* the structure of a symbol table entry */ @@ -305,9 +305,9 @@ extern short final_state; /* global functions */ -extern char *allocate(); -extern bucket *lookup(); -extern bucket *make_bucket(); +extern void *allocate(size_t); +extern bucket *lookup(char *); +extern bucket *make_bucket(char *); extern void set_first_derives(void); extern void closure(short *, int); extern void finalize_closure(void); diff --git a/usr.bin/yacc/lr0.c b/usr.bin/yacc/lr0.c index a7632093898..10e4b2146c4 100644 --- a/usr.bin/yacc/lr0.c +++ b/usr.bin/yacc/lr0.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lr0.c,v 1.13 2014/01/08 21:40:25 millert Exp $ */ +/* $OpenBSD: lr0.c,v 1.14 2014/01/08 22:30:32 millert Exp $ */ /* $NetBSD: lr0.c,v 1.4 1996/03/19 03:21:35 jtc Exp $ */ /* @@ -343,7 +343,7 @@ new_state(int symbol) iend = kernel_end[symbol]; n = iend - isp1; - p = (core *) allocate((unsigned) (sizeof(core) + (n - 1) * sizeof(short))); + p = allocate(sizeof(core) + (n - 1) * sizeof(short)); p->accessing_symbol = symbol; p->number = nstates; p->nitems = n; @@ -369,8 +369,7 @@ save_shifts(void) short *sp2; short *send; - p = (shifts *) allocate((unsigned) (sizeof(shifts) + - (nshifts - 1) * sizeof(short))); + p = allocate(sizeof(shifts) + (nshifts - 1) * sizeof(short)); p->number = this_state->number; p->nshifts = nshifts; @@ -418,8 +417,7 @@ save_reductions(void) if (count) { - p = (reductions *) allocate((unsigned) (sizeof(reductions) + - (count - 1) * sizeof(short))); + p = allocate(sizeof(reductions) + (count - 1) * sizeof(short)); p->number = this_state->number; p->nreds = count; diff --git a/usr.bin/yacc/main.c b/usr.bin/yacc/main.c index 2a2384a2249..77a343d6278 100644 --- a/usr.bin/yacc/main.c +++ b/usr.bin/yacc/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.24 2014/01/08 21:40:25 millert Exp $ */ +/* $OpenBSD: main.c,v 1.25 2014/01/08 22:30:32 millert Exp $ */ /* $NetBSD: main.c,v 1.5 1996/03/19 03:21:38 jtc Exp $ */ /* @@ -213,18 +213,18 @@ getargs(int argc, char *argv[]) } -char * -allocate(unsigned int n) +void * +allocate(size_t n) { - char *p; + void *v; - p = NULL; + v = NULL; if (n) { - p = calloc(1, n); - if (!p) no_space(); + v = calloc(1, n); + if (!v) no_space(); } - return (p); + return (v); } #define TEMPNAME(s, c, d, l) \ -- 2.20.1