diff options
| author | christos <christos@NetBSD.org> | 1998-03-26 19:20:36 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 1998-03-26 19:20:36 +0000 |
| commit | f46f2d693ea899371cf704323e0db1dbff3765c7 (patch) | |
| tree | c5ccdf0415543ce8bad914b7d0c8182f8b26fa03 /usr.bin/make/str.c | |
| parent | 531db9e0d34f755c147d58f79e07983fea5e522d (diff) | |
PR/5210: Hauke Fath: make core dumps with .SHELL
Unfortunately this revealed a deeper problem with the brk_string code.
To fix it:
- remove sharing of the buffer between brk_string invocations
- change the semantics of brk_string so that the argument array
starts with 0, and return the buffer where the strings are
stored
Diffstat (limited to 'usr.bin/make/str.c')
| -rw-r--r-- | usr.bin/make/str.c | 56 |
1 files changed, 11 insertions, 45 deletions
diff --git a/usr.bin/make/str.c b/usr.bin/make/str.c index 492bc6be435..dcee265b3ec 100644 --- a/usr.bin/make/str.c +++ b/usr.bin/make/str.c @@ -1,4 +1,4 @@ -/* $NetBSD: str.c,v 1.15 1997/09/28 03:31:10 lukem Exp $ */ +/* $NetBSD: str.c,v 1.16 1998/03/26 19:20:37 christos Exp $ */ /*- * Copyright (c) 1988, 1989, 1990, 1993 @@ -39,54 +39,20 @@ */ #ifdef MAKE_BOOTSTRAP -static char rcsid[] = "$NetBSD: str.c,v 1.15 1997/09/28 03:31:10 lukem Exp $"; +static char rcsid[] = "$NetBSD: str.c,v 1.16 1998/03/26 19:20:37 christos Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)str.c 5.8 (Berkeley) 6/1/90"; #else -__RCSID("$NetBSD: str.c,v 1.15 1997/09/28 03:31:10 lukem Exp $"); +__RCSID("$NetBSD: str.c,v 1.16 1998/03/26 19:20:37 christos Exp $"); #endif #endif /* not lint */ #endif #include "make.h" -static char **argv, *buffer; -static int argmax, curlen; - -/* - * str_init -- - * Initialize the strings package - * - */ -void -str_init() -{ - char *p1; - argv = (char **)emalloc(((argmax = 50) + 1) * sizeof(char *)); - argv[0] = Var_Value(".MAKE", VAR_GLOBAL, &p1); -} - - -/* - * str_end -- - * Cleanup the strings package - * - */ -void -str_end() -{ - if (argv) { - if (argv[0]) - free(argv[0]); - free((Address) argv); - } - if (buffer) - free(buffer); -} - /*- * str_concat -- * concatenate the two strings, inserting a space or slash between them, @@ -144,33 +110,33 @@ str_concat(s1, s2, flags) * the first word is always the value of the .MAKE variable. */ char ** -brk_string(str, store_argc, expand) +brk_string(str, store_argc, expand, buffer) register char *str; int *store_argc; Boolean expand; + char **buffer; { register int argc, ch; register char inquote, *p, *start, *t; int len; + int argmax = 50, curlen = 0; + char **argv = (char **)emalloc((argmax + 1) * sizeof(char *)); /* skip leading space chars. */ for (; *str == ' ' || *str == '\t'; ++str) continue; /* allocate room for a copy of the string */ - if ((len = strlen(str) + 1) > curlen) { - if (buffer) - free(buffer); - buffer = emalloc(curlen = len); - } + if ((len = strlen(str) + 1) > curlen) + *buffer = emalloc(curlen = len); /* * copy the string; at the same time, parse backslashes, * quotes and build the argument list. */ - argc = 1; + argc = 0; inquote = '\0'; - for (p = str, start = t = buffer;; ++p) { + for (p = str, start = t = *buffer;; ++p) { switch(ch = *p) { case '"': case '\'': |
