-/* $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
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);
}
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;
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;
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;