Mon Nov 2 21:15:00 2020 UTC ()
make(1): document that skipping a modifier on parse errors is risky


(rillig)
diff -r1.649 -r1.650 src/usr.bin/make/var.c

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

--- src/usr.bin/make/var.c 2020/11/02 20:48:36 1.649
+++ src/usr.bin/make/var.c 2020/11/02 21:15:00 1.650
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: var.c,v 1.649 2020/11/02 20:48:36 rillig Exp $ */ 1/* $NetBSD: var.c,v 1.650 2020/11/02 21:15:00 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.
@@ -120,27 +120,27 @@ @@ -120,27 +120,27 @@
120#include <regex.h> 120#include <regex.h>
121#endif 121#endif
122#include <errno.h> 122#include <errno.h>
123#include <inttypes.h> 123#include <inttypes.h>
124#include <limits.h> 124#include <limits.h>
125#include <time.h> 125#include <time.h>
126 126
127#include "make.h" 127#include "make.h"
128#include "dir.h" 128#include "dir.h"
129#include "job.h" 129#include "job.h"
130#include "metachar.h" 130#include "metachar.h"
131 131
132/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ 132/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
133MAKE_RCSID("$NetBSD: var.c,v 1.649 2020/11/02 20:48:36 rillig Exp $"); 133MAKE_RCSID("$NetBSD: var.c,v 1.650 2020/11/02 21:15:00 rillig Exp $");
134 134
135#define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1) 135#define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1)
136#define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2) 136#define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2)
137#define VAR_DEBUG3(fmt, arg1, arg2, arg3) DEBUG3(VAR, fmt, arg1, arg2, arg3) 137#define VAR_DEBUG3(fmt, arg1, arg2, arg3) DEBUG3(VAR, fmt, arg1, arg2, arg3)
138#define VAR_DEBUG4(fmt, arg1, arg2, arg3, arg4) DEBUG4(VAR, fmt, arg1, arg2, arg3, arg4) 138#define VAR_DEBUG4(fmt, arg1, arg2, arg3, arg4) DEBUG4(VAR, fmt, arg1, arg2, arg3, arg4)
139 139
140ENUM_FLAGS_RTTI_3(VarEvalFlags, 140ENUM_FLAGS_RTTI_3(VarEvalFlags,
141 VARE_UNDEFERR, VARE_WANTRES, VARE_ASSIGN); 141 VARE_UNDEFERR, VARE_WANTRES, VARE_ASSIGN);
142 142
143/* 143/*
144 * This lets us tell if we have replaced the original environ 144 * This lets us tell if we have replaced the original environ
145 * (which we cannot free). 145 * (which we cannot free).
146 */ 146 */
@@ -3381,26 +3381,29 @@ ApplyModifiers( @@ -3381,26 +3381,29 @@ ApplyModifiers(
3381 LogBeforeApply(&st, mod, endc); 3381 LogBeforeApply(&st, mod, endc);
3382 3382
3383 res = ApplyModifier(&p, &st); 3383 res = ApplyModifier(&p, &st);
3384 3384
3385#ifdef SYSVVARSUB 3385#ifdef SYSVVARSUB
3386 if (res == AMR_UNKNOWN) { 3386 if (res == AMR_UNKNOWN) {
3387 assert(p == mod); 3387 assert(p == mod);
3388 res = ApplyModifier_SysV(&p, &st); 3388 res = ApplyModifier_SysV(&p, &st);
3389 } 3389 }
3390#endif 3390#endif
3391 3391
3392 if (res == AMR_UNKNOWN) { 3392 if (res == AMR_UNKNOWN) {
3393 Error("Unknown modifier '%c'", *mod); 3393 Error("Unknown modifier '%c'", *mod);
 3394 /* Guess the end of the current modifier.
 3395 * XXX: Skipping the rest of the modifier hides errors and leads
 3396 * to wrong results. Parsing should rather stop here. */
3394 for (p++; *p != ':' && *p != st.endc && *p != '\0'; p++) 3397 for (p++; *p != ':' && *p != st.endc && *p != '\0'; p++)
3395 continue; 3398 continue;
3396 st.newVal = var_Error; 3399 st.newVal = var_Error;
3397 } 3400 }
3398 if (res == AMR_CLEANUP) 3401 if (res == AMR_CLEANUP)
3399 goto cleanup; 3402 goto cleanup;
3400 if (res == AMR_BAD) 3403 if (res == AMR_BAD)
3401 goto bad_modifier; 3404 goto bad_modifier;
3402 3405
3403 if (DEBUG(VAR)) 3406 if (DEBUG(VAR))
3404 LogAfterApply(&st, p, mod); 3407 LogAfterApply(&st, p, mod);
3405 3408
3406 if (st.newVal != st.val) { 3409 if (st.newVal != st.val) {