Sat Aug 29 11:24:54 2020 UTC ()
make(1): add bmake_strsedup for duplicating a substring


(rillig)
diff -r1.15 -r1.16 src/usr.bin/make/make_malloc.c
diff -r1.8 -r1.9 src/usr.bin/make/make_malloc.h
diff -r1.270 -r1.271 src/usr.bin/make/parse.c
diff -r1.132 -r1.133 src/usr.bin/make/suff.c
diff -r1.473 -r1.474 src/usr.bin/make/var.c

cvs diff -r1.15 -r1.16 src/usr.bin/make/make_malloc.c (expand / switch to unified diff)

--- src/usr.bin/make/make_malloc.c 2020/08/20 06:35:14 1.15
+++ src/usr.bin/make/make_malloc.c 2020/08/29 11:24:54 1.16
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: make_malloc.c,v 1.15 2020/08/20 06:35:14 rillig Exp $ */ 1/* $NetBSD: make_malloc.c,v 1.16 2020/08/29 11:24:54 rillig Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2009 The NetBSD Foundation, Inc. 4 * Copyright (c) 2009 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -18,27 +18,27 @@ @@ -18,27 +18,27 @@
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#ifdef MAKE_NATIVE 29#ifdef MAKE_NATIVE
30#include <sys/cdefs.h> 30#include <sys/cdefs.h>
31__RCSID("$NetBSD: make_malloc.c,v 1.15 2020/08/20 06:35:14 rillig Exp $"); 31__RCSID("$NetBSD: make_malloc.c,v 1.16 2020/08/29 11:24:54 rillig Exp $");
32#endif 32#endif
33 33
34#include <stdio.h> 34#include <stdio.h>
35#include <stdlib.h> 35#include <stdlib.h>
36#include <string.h> 36#include <string.h>
37#include <errno.h> 37#include <errno.h>
38 38
39#include "make.h" 39#include "make.h"
40 40
41#ifndef USE_EMALLOC 41#ifndef USE_EMALLOC
42static MAKE_ATTR_DEAD void enomem(void); 42static MAKE_ATTR_DEAD void enomem(void);
43 43
44/* 44/*
@@ -82,25 +82,32 @@ bmake_strdup(const char *str) @@ -82,25 +82,32 @@ bmake_strdup(const char *str)
82 return memcpy(p, str, len); 82 return memcpy(p, str, len);
83} 83}
84 84
85/* Allocate a string starting from str with exactly len characters. */ 85/* Allocate a string starting from str with exactly len characters. */
86char * 86char *
87bmake_strldup(const char *str, size_t len) 87bmake_strldup(const char *str, size_t len)
88{ 88{
89 char *p = bmake_malloc(len + 1); 89 char *p = bmake_malloc(len + 1);
90 memcpy(p, str, len); 90 memcpy(p, str, len);
91 p[len] = '\0'; 91 p[len] = '\0';
92 return p; 92 return p;
93} 93}
94 94
 95/* Allocate a string from start up to but excluding end. */
 96char *
 97bmake_strsedup(const char *start, const char *end)
 98{
 99 return bmake_strldup(start, (size_t)(end - start));
 100}
 101
95/* 102/*
96 * bmake_realloc -- 103 * bmake_realloc --
97 * realloc, but die on error. 104 * realloc, but die on error.
98 */ 105 */
99void * 106void *
100bmake_realloc(void *ptr, size_t size) 107bmake_realloc(void *ptr, size_t size)
101{ 108{
102 if ((ptr = realloc(ptr, size)) == NULL) 109 if ((ptr = realloc(ptr, size)) == NULL)
103 enomem(); 110 enomem();
104 return ptr; 111 return ptr;
105} 112}
106#endif 113#endif

cvs diff -r1.8 -r1.9 src/usr.bin/make/make_malloc.h (expand / switch to unified diff)

--- src/usr.bin/make/make_malloc.h 2020/08/25 17:37:09 1.8
+++ src/usr.bin/make/make_malloc.h 2020/08/29 11:24:54 1.9
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: make_malloc.h,v 1.8 2020/08/25 17:37:09 rillig Exp $ */ 1/* $NetBSD: make_malloc.h,v 1.9 2020/08/29 11:24:54 rillig Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2009 The NetBSD Foundation, Inc. 4 * Copyright (c) 2009 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -21,26 +21,27 @@ @@ -21,26 +21,27 @@
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#ifndef USE_EMALLOC 29#ifndef USE_EMALLOC
30void *bmake_malloc(size_t); 30void *bmake_malloc(size_t);
31void *bmake_realloc(void *, size_t); 31void *bmake_realloc(void *, size_t);
32char *bmake_strdup(const char *); 32char *bmake_strdup(const char *);
33char *bmake_strldup(const char *, size_t); 33char *bmake_strldup(const char *, size_t);
 34char *bmake_strsedup(const char *, const char *);
34#else 35#else
35#include <util.h> 36#include <util.h>
36#define bmake_malloc(x) emalloc(x) 37#define bmake_malloc(x) emalloc(x)
37#define bmake_realloc(x,y) erealloc(x,y) 38#define bmake_realloc(x,y) erealloc(x,y)
38#define bmake_strdup(x) estrdup(x) 39#define bmake_strdup(x) estrdup(x)
39#define bmake_strldup(x,y) estrndup(x,y) 40#define bmake_strldup(x,y) estrndup(x,y)
40#endif 41#endif
41 42
42/* Thin wrapper around free(3) to avoid the extra function call in case 43/* Thin wrapper around free(3) to avoid the extra function call in case
43 * p is NULL, which on x86_64 costs about 12 machine instructions. 44 * p is NULL, which on x86_64 costs about 12 machine instructions.
44 * Other platforms are similarly affected. 45 * Other platforms are similarly affected.
45 * 46 *
46 * The case of a NULL pointer happens especially often after Var_Value, 47 * The case of a NULL pointer happens especially often after Var_Value,

cvs diff -r1.270 -r1.271 src/usr.bin/make/parse.c (expand / switch to unified diff)

--- src/usr.bin/make/parse.c 2020/08/29 11:13:43 1.270
+++ src/usr.bin/make/parse.c 2020/08/29 11:24:54 1.271
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: parse.c,v 1.270 2020/08/29 11:13:43 rillig Exp $ */ 1/* $NetBSD: parse.c,v 1.271 2020/08/29 11:24:54 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -59,34 +59,34 @@ @@ -59,34 +59,34 @@
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE. 68 * SUCH DAMAGE.
69 */ 69 */
70 70
71#ifndef MAKE_NATIVE 71#ifndef MAKE_NATIVE
72static char rcsid[] = "$NetBSD: parse.c,v 1.270 2020/08/29 11:13:43 rillig Exp $"; 72static char rcsid[] = "$NetBSD: parse.c,v 1.271 2020/08/29 11:24:54 rillig Exp $";
73#else 73#else
74#include <sys/cdefs.h> 74#include <sys/cdefs.h>
75#ifndef lint 75#ifndef lint
76#if 0 76#if 0
77static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94"; 77static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94";
78#else 78#else
79__RCSID("$NetBSD: parse.c,v 1.270 2020/08/29 11:13:43 rillig Exp $"); 79__RCSID("$NetBSD: parse.c,v 1.271 2020/08/29 11:24:54 rillig Exp $");
80#endif 80#endif
81#endif /* not lint */ 81#endif /* not lint */
82#endif 82#endif
83 83
84/*- 84/*-
85 * parse.c -- 85 * parse.c --
86 * Functions to parse a makefile. 86 * Functions to parse a makefile.
87 * 87 *
88 * One function, Parse_Init, must be called before any functions 88 * One function, Parse_Init, must be called before any functions
89 * in this module are used. After that, the function Parse_File is the 89 * in this module are used. After that, the function Parse_File is the
90 * main entry point and controls most of the other functions in this 90 * main entry point and controls most of the other functions in this
91 * module. 91 * module.
92 * 92 *
@@ -2392,27 +2392,27 @@ ParseSetIncludedFile(void) @@ -2392,27 +2392,27 @@ ParseSetIncludedFile(void)
2392 */ 2392 */
2393static void 2393static void
2394ParseSetParseFile(const char *filename) 2394ParseSetParseFile(const char *filename)
2395{ 2395{
2396 char *slash, *dirname; 2396 char *slash, *dirname;
2397 const char *pd, *pf; 2397 const char *pd, *pf;
2398 2398
2399 slash = strrchr(filename, '/'); 2399 slash = strrchr(filename, '/');
2400 if (slash == NULL) { 2400 if (slash == NULL) {
2401 Var_Set(".PARSEDIR", pd = curdir, VAR_GLOBAL); 2401 Var_Set(".PARSEDIR", pd = curdir, VAR_GLOBAL);
2402 Var_Set(".PARSEFILE", pf = filename, VAR_GLOBAL); 2402 Var_Set(".PARSEFILE", pf = filename, VAR_GLOBAL);
2403 dirname = NULL; 2403 dirname = NULL;
2404 } else { 2404 } else {
2405 dirname = bmake_strldup(filename, (size_t)(slash - filename)); 2405 dirname = bmake_strsedup(filename, slash);
2406 Var_Set(".PARSEDIR", pd = dirname, VAR_GLOBAL); 2406 Var_Set(".PARSEDIR", pd = dirname, VAR_GLOBAL);
2407 Var_Set(".PARSEFILE", pf = slash + 1, VAR_GLOBAL); 2407 Var_Set(".PARSEFILE", pf = slash + 1, VAR_GLOBAL);
2408 } 2408 }
2409 if (DEBUG(PARSE)) 2409 if (DEBUG(PARSE))
2410 fprintf(debug_file, "%s: ${.PARSEDIR} = `%s' ${.PARSEFILE} = `%s'\n", 2410 fprintf(debug_file, "%s: ${.PARSEDIR} = `%s' ${.PARSEFILE} = `%s'\n",
2411 __func__, pd, pf); 2411 __func__, pd, pf);
2412 free(dirname); 2412 free(dirname);
2413} 2413}
2414 2414
2415/* 2415/*
2416 * Track the makefiles we read - so makefiles can 2416 * Track the makefiles we read - so makefiles can
2417 * set dependencies on them. 2417 * set dependencies on them.
2418 * Avoid adding anything more than once. 2418 * Avoid adding anything more than once.

cvs diff -r1.132 -r1.133 src/usr.bin/make/suff.c (expand / switch to unified diff)

--- src/usr.bin/make/suff.c 2020/08/29 11:13:43 1.132
+++ src/usr.bin/make/suff.c 2020/08/29 11:24:54 1.133
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: suff.c,v 1.132 2020/08/29 11:13:43 rillig Exp $ */ 1/* $NetBSD: suff.c,v 1.133 2020/08/29 11:24:54 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -59,34 +59,34 @@ @@ -59,34 +59,34 @@
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE. 68 * SUCH DAMAGE.
69 */ 69 */
70 70
71#ifndef MAKE_NATIVE 71#ifndef MAKE_NATIVE
72static char rcsid[] = "$NetBSD: suff.c,v 1.132 2020/08/29 11:13:43 rillig Exp $"; 72static char rcsid[] = "$NetBSD: suff.c,v 1.133 2020/08/29 11:24:54 rillig Exp $";
73#else 73#else
74#include <sys/cdefs.h> 74#include <sys/cdefs.h>
75#ifndef lint 75#ifndef lint
76#if 0 76#if 0
77static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94"; 77static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94";
78#else 78#else
79__RCSID("$NetBSD: suff.c,v 1.132 2020/08/29 11:13:43 rillig Exp $"); 79__RCSID("$NetBSD: suff.c,v 1.133 2020/08/29 11:24:54 rillig Exp $");
80#endif 80#endif
81#endif /* not lint */ 81#endif /* not lint */
82#endif 82#endif
83 83
84/*- 84/*-
85 * suff.c -- 85 * suff.c --
86 * Functions to maintain suffix lists and find implicit dependents 86 * Functions to maintain suffix lists and find implicit dependents
87 * using suffix transformation rules 87 * using suffix transformation rules
88 * 88 *
89 * Interface: 89 * Interface:
90 * Suff_Init Initialize all things to do with suffixes. 90 * Suff_Init Initialize all things to do with suffixes.
91 * 91 *
92 * Suff_End Cleanup the module 92 * Suff_End Cleanup the module
@@ -2027,27 +2027,27 @@ SuffFindNormalDeps(GNode *gn, Lst slst) @@ -2027,27 +2027,27 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
2027 */ 2027 */
2028 targ = bmake_malloc(sizeof(Src)); 2028 targ = bmake_malloc(sizeof(Src));
2029 targ->file = bmake_strdup(gn->name); 2029 targ->file = bmake_strdup(gn->name);
2030 targ->suff = Lst_Datum(ln); 2030 targ->suff = Lst_Datum(ln);
2031 targ->suff->refCount++; 2031 targ->suff->refCount++;
2032 targ->node = gn; 2032 targ->node = gn;
2033 targ->parent = NULL; 2033 targ->parent = NULL;
2034 targ->children = 0; 2034 targ->children = 0;
2035#ifdef DEBUG_SRC 2035#ifdef DEBUG_SRC
2036 targ->cp = Lst_Init(); 2036 targ->cp = Lst_Init();
2037#endif 2037#endif
2038 2038
2039 eopref = eoname - targ->suff->nameLen; 2039 eopref = eoname - targ->suff->nameLen;
2040 targ->pref = bmake_strldup(sopref, (size_t)(eopref - sopref)); 2040 targ->pref = bmake_strsedup(sopref, eopref);
2041 2041
2042 /* 2042 /*
2043 * Add nodes from which the target can be made 2043 * Add nodes from which the target can be made
2044 */ 2044 */
2045 SuffAddLevel(srcs, targ); 2045 SuffAddLevel(srcs, targ);
2046 2046
2047 /* 2047 /*
2048 * Record the target so we can nuke it 2048 * Record the target so we can nuke it
2049 */ 2049 */
2050 Lst_Append(targs, targ); 2050 Lst_Append(targs, targ);
2051 2051
2052 /* 2052 /*
2053 * Search from this suffix's successor... 2053 * Search from this suffix's successor...

cvs diff -r1.473 -r1.474 src/usr.bin/make/var.c (expand / switch to unified diff)

--- src/usr.bin/make/var.c 2020/08/29 07:52:55 1.473
+++ src/usr.bin/make/var.c 2020/08/29 11:24:54 1.474
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: var.c,v 1.473 2020/08/29 07:52:55 rillig Exp $ */ 1/* $NetBSD: var.c,v 1.474 2020/08/29 11:24:54 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -59,34 +59,34 @@ @@ -59,34 +59,34 @@
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE. 68 * SUCH DAMAGE.
69 */ 69 */
70 70
71#ifndef MAKE_NATIVE 71#ifndef MAKE_NATIVE
72static char rcsid[] = "$NetBSD: var.c,v 1.473 2020/08/29 07:52:55 rillig Exp $"; 72static char rcsid[] = "$NetBSD: var.c,v 1.474 2020/08/29 11:24:54 rillig Exp $";
73#else 73#else
74#include <sys/cdefs.h> 74#include <sys/cdefs.h>
75#ifndef lint 75#ifndef lint
76#if 0 76#if 0
77static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94"; 77static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
78#else 78#else
79__RCSID("$NetBSD: var.c,v 1.473 2020/08/29 07:52:55 rillig Exp $"); 79__RCSID("$NetBSD: var.c,v 1.474 2020/08/29 11:24:54 rillig Exp $");
80#endif 80#endif
81#endif /* not lint */ 81#endif /* not lint */
82#endif 82#endif
83 83
84/*- 84/*-
85 * var.c -- 85 * var.c --
86 * Variable-handling functions 86 * Variable-handling functions
87 * 87 *
88 * Interface: 88 * Interface:
89 * Var_Set Set the value of a variable in the given 89 * Var_Set Set the value of a variable in the given
90 * context. The variable is created if it doesn't 90 * context. The variable is created if it doesn't
91 * yet exist. 91 * yet exist.
92 * 92 *
@@ -2302,31 +2302,27 @@ ApplyModifier_Match(const char **pp, App @@ -2302,31 +2302,27 @@ ApplyModifier_Match(const char **pp, App
2302 pattern = bmake_malloc((size_t)(endpat - (mod + 1)) + 1); 2302 pattern = bmake_malloc((size_t)(endpat - (mod + 1)) + 1);
2303 dst = pattern; 2303 dst = pattern;
2304 src = mod + 1; 2304 src = mod + 1;
2305 for (; src < endpat; src++, dst++) { 2305 for (; src < endpat; src++, dst++) {
2306 if (src[0] == '\\' && src + 1 < endpat && 2306 if (src[0] == '\\' && src + 1 < endpat &&
2307 /* XXX: st->startc is missing here; see above */ 2307 /* XXX: st->startc is missing here; see above */
2308 (src[1] == ':' || src[1] == st->endc)) 2308 (src[1] == ':' || src[1] == st->endc))
2309 src++; 2309 src++;
2310 *dst = *src; 2310 *dst = *src;
2311 } 2311 }
2312 *dst = '\0'; 2312 *dst = '\0';
2313 endpat = dst; 2313 endpat = dst;
2314 } else { 2314 } else {
2315 /* 2315 pattern = bmake_strsedup(mod + 1, endpat);
2316 * Either Var_Subst or ModifyWords will need a 
2317 * nul-terminated string soon, so construct one now. 
2318 */ 
2319 pattern = bmake_strldup(mod + 1, (size_t)(endpat - (mod + 1))); 
2320 } 2316 }
2321 2317
2322 if (needSubst) { 2318 if (needSubst) {
2323 /* pattern contains embedded '$', so use Var_Subst to expand it. */ 2319 /* pattern contains embedded '$', so use Var_Subst to expand it. */
2324 char *old_pattern = pattern; 2320 char *old_pattern = pattern;
2325 pattern = Var_Subst(pattern, st->ctxt, st->eflags); 2321 pattern = Var_Subst(pattern, st->ctxt, st->eflags);
2326 free(old_pattern); 2322 free(old_pattern);
2327 } 2323 }
2328 2324
2329 VAR_DEBUG("Pattern[%s] for [%s] is [%s]\n", st->v->name, st->val, pattern); 2325 VAR_DEBUG("Pattern[%s] for [%s] is [%s]\n", st->v->name, st->val, pattern);
2330 2326
2331 callback = mod[0] == 'M' ? ModifyWord_Match : ModifyWord_NoMatch; 2327 callback = mod[0] == 'M' ? ModifyWord_Match : ModifyWord_NoMatch;
2332 st->newVal = ModifyWords(st->ctxt, st->sep, st->oneBigWord, st->val, 2328 st->newVal = ModifyWords(st->ctxt, st->sep, st->oneBigWord, st->val,