From: tedu Date: Tue, 6 May 2014 15:48:38 +0000 (+0000) Subject: reallocarray for things which are arrays. ok deraadt X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=b7ac5991afdbf42dcf27f12a6636148da658e2be;p=openbsd reallocarray for things which are arrays. ok deraadt --- diff --git a/lib/libc/regex/regcomp.c b/lib/libc/regex/regcomp.c index 109b4a21744..d49b921302d 100644 --- a/lib/libc/regex/regcomp.c +++ b/lib/libc/regex/regcomp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: regcomp.c,v 1.23 2013/11/26 13:16:18 deraadt Exp $ */ +/* $OpenBSD: regcomp.c,v 1.24 2014/05/06 15:48:38 tedu Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 Henry Spencer. * Copyright (c) 1992, 1993, 1994 @@ -171,14 +171,14 @@ regcomp(regex_t *preg, const char *pattern, int cflags) len = strlen((char *)pattern); /* do the mallocs early so failure handling is easy */ - g = (struct re_guts *)malloc(sizeof(struct re_guts)); + g = malloc(sizeof(struct re_guts)); if (g == NULL) return(REG_ESPACE); p->ssize = len/(size_t)2*(size_t)3 + (size_t)1; /* ugh */ - p->strip = (sop *)calloc(p->ssize, sizeof(sop)); + p->strip = reallocarray(NULL, p->ssize, sizeof(sop)); p->slen = 0; if (p->strip == NULL) { - free((char *)g); + free(g); return(REG_ESPACE); } @@ -1023,12 +1023,12 @@ allocset(struct parse *p) assert(nc % CHAR_BIT == 0); nbytes = nc / CHAR_BIT * css; - ptr = (cset *)realloc((char *)p->g->sets, nc * sizeof(cset)); + ptr = reallocarray(p->g->sets, nc, sizeof(cset)); if (ptr == NULL) goto nomem; p->g->sets = ptr; - ptr = (uch *)realloc((char *)p->g->setbits, nbytes); + ptr = realloc(p->g->setbits, nbytes); if (ptr == NULL) goto nomem; p->g->setbits = ptr; @@ -1363,7 +1363,7 @@ enlarge(struct parse *p, sopno size) if (p->ssize >= size) return 1; - sp = (sop *)realloc(p->strip, size*sizeof(sop)); + sp = reallocarray(p->strip, size, sizeof(sop)); if (sp == NULL) { SETERROR(REG_ESPACE); return 0; @@ -1380,7 +1380,7 @@ static void stripsnug(struct parse *p, struct re_guts *g) { g->nstates = p->slen; - g->strip = (sop *)realloc((char *)p->strip, p->slen * sizeof(sop)); + g->strip = reallocarray(p->strip, p->slen, sizeof(sop)); if (g->strip == NULL) { SETERROR(REG_ESPACE); g->strip = p->strip;