eliminate alloca use.

This commit is contained in:
christos 2006-11-09 20:50:53 +00:00
parent 10891a6668
commit 1dcd74fde3
2 changed files with 14 additions and 7 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: function.c,v 1.58 2006/10/12 08:46:18 tacha Exp $ */
/* $NetBSD: function.c,v 1.59 2006/11/09 20:50:53 christos Exp $ */
/*-
* Copyright (c) 1990, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "from: @(#)function.c 8.10 (Berkeley) 5/4/95";
#else
__RCSID("$NetBSD: function.c,v 1.58 2006/10/12 08:46:18 tacha Exp $");
__RCSID("$NetBSD: function.c,v 1.59 2006/11/09 20:50:53 christos Exp $");
#endif
#endif /* not lint */
@ -1509,14 +1509,19 @@ c_regex_common(char ***argvp, int isok, enum ntype type, int regcomp_flags)
char *lineregexp;
PLAN *new;
int rv;
size_t len;
(*argvp)++;
lineregexp = alloca(strlen(regexp) + 1 + 6); /* max needed */
sprintf(lineregexp, "^%s(%s%s)$",
len = strlen(regexp) + 1 + 6;
lineregexp = malloc(len); /* max needed */
if (lineregexp == NULL)
err(1, NULL);
snprintf(lineregexp, len, "^%s(%s%s)$",
(regcomp_flags & REG_EXTENDED) ? "" : "\\", regexp,
(regcomp_flags & REG_EXTENDED) ? "" : "\\");
rv = regcomp(&reg, lineregexp, REG_NOSUB|regcomp_flags);
free(lineregexp);
if (rv != 0) {
regerror(rv, &reg, errbuf, sizeof errbuf);
errx(1, "regexp %s: %s", regexp, errbuf);

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.25 2006/10/11 19:51:10 apb Exp $ */
/* $NetBSD: main.c,v 1.26 2006/11/09 20:50:53 christos Exp $ */
/*-
* Copyright (c) 1990, 1993, 1994
@ -39,7 +39,7 @@ static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 5/4/95";
#else
__COPYRIGHT("@(#) Copyright (c) 1990, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n");
__RCSID("$NetBSD: main.c,v 1.25 2006/10/11 19:51:10 apb Exp $");
__RCSID("$NetBSD: main.c,v 1.26 2006/11/09 20:50:53 christos Exp $");
#endif
#endif /* not lint */
@ -88,7 +88,9 @@ main(int argc, char *argv[])
sigaction(SIGINFO, &sa, NULL);
/* array to hold dir list. at most (argc - 1) elements. */
p = start = alloca(argc * sizeof (char *));
p = start = malloc(argc * sizeof (char *));
if (p == NULL)
err(1, NULL);
ftsoptions = FTS_NOSTAT | FTS_PHYSICAL;
while ((ch = getopt(argc, argv, "HLPXdf:hsx")) != -1)