| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: var.c,v 1.498 2020/09/12 18:45:24 rillig Exp $ */ | | 1 | /* $NetBSD: var.c,v 1.499 2020/09/12 19:13:43 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 |
72 | static char rcsid[] = "$NetBSD: var.c,v 1.498 2020/09/12 18:45:24 rillig Exp $"; | | 72 | static char rcsid[] = "$NetBSD: var.c,v 1.499 2020/09/12 19:13:43 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 |
77 | static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94"; | | 77 | static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94"; |
78 | #else | | 78 | #else |
79 | __RCSID("$NetBSD: var.c,v 1.498 2020/09/12 18:45:24 rillig Exp $"); | | 79 | __RCSID("$NetBSD: var.c,v 1.499 2020/09/12 19:13:43 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 | * |
| @@ -3578,35 +3578,33 @@ Var_Parse(const char **pp, GNode *ctxt, | | | @@ -3578,35 +3578,33 @@ Var_Parse(const char **pp, GNode *ctxt, |
3578 | | | 3578 | |
3579 | nstr = ApplyModifiers(&p, nstr, startc, endc, | | 3579 | nstr = ApplyModifiers(&p, nstr, startc, endc, |
3580 | v, ctxt, eflags, freePtr); | | 3580 | v, ctxt, eflags, freePtr); |
3581 | free(extraFree); | | 3581 | free(extraFree); |
3582 | } else { | | 3582 | } else { |
3583 | *freePtr = extraFree; | | 3583 | *freePtr = extraFree; |
3584 | } | | 3584 | } |
3585 | } | | 3585 | } |
3586 | | | 3586 | |
3587 | /* Skip past endc if possible. */ | | 3587 | /* Skip past endc if possible. */ |
3588 | *pp = p + (*p ? 1 : 0); | | 3588 | *pp = p + (*p ? 1 : 0); |
3589 | | | 3589 | |
3590 | if (v->flags & VAR_FROM_ENV) { | | 3590 | if (v->flags & VAR_FROM_ENV) { |
3591 | Boolean destroy = nstr != Buf_GetAll(&v->val, NULL); | | 3591 | /* Free the environment variable now since we own it, |
3592 | if (!destroy) { | | 3592 | * but don't free the variable value if it will be returned. */ |
3593 | /* | | 3593 | Boolean keepValue = nstr == Buf_GetAll(&v->val, NULL); |
3594 | * Returning the value unmodified, so tell the caller to free | | 3594 | if (keepValue) |
3595 | * the thing. | | | |
3596 | */ | | | |
3597 | *freePtr = nstr; | | 3595 | *freePtr = nstr; |
3598 | } | | 3596 | (void)VarFreeEnv(v, !keepValue); |
3599 | (void)VarFreeEnv(v, destroy); | | 3597 | |
3600 | } else if (v->flags & VAR_JUNK) { | | 3598 | } else if (v->flags & VAR_JUNK) { |
3601 | /* | | 3599 | /* |
3602 | * Perform any freeing needed and set *freePtr to NULL so the caller | | 3600 | * Perform any freeing needed and set *freePtr to NULL so the caller |
3603 | * doesn't try to free a static pointer. | | 3601 | * doesn't try to free a static pointer. |
3604 | * If VAR_KEEP is also set then we want to keep str(?) as is. | | 3602 | * If VAR_KEEP is also set then we want to keep str(?) as is. |
3605 | */ | | 3603 | */ |
3606 | if (!(v->flags & VAR_KEEP)) { | | 3604 | if (!(v->flags & VAR_KEEP)) { |
3607 | if (*freePtr != NULL) { | | 3605 | if (*freePtr != NULL) { |
3608 | free(*freePtr); | | 3606 | free(*freePtr); |
3609 | *freePtr = NULL; | | 3607 | *freePtr = NULL; |
3610 | } | | 3608 | } |
3611 | if (dynamic) { | | 3609 | if (dynamic) { |
3612 | nstr = bmake_strldup(start, (size_t)(*pp - start)); | | 3610 | nstr = bmake_strldup(start, (size_t)(*pp - start)); |