Module Name: src Committed By: rillig Date: Sun Nov 19 11:47:49 UTC 2023
Modified Files: src/usr.bin/make: var.c src/usr.bin/make/unit-tests: varmod-mtime.exp varmod-mtime.mk Log Message: make: produce more accurate error message for invalid ':mtime' argument To generate a diff of this commit: cvs rdiff -u -r1.1071 -r1.1072 src/usr.bin/make/var.c cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/varmod-mtime.exp cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/varmod-mtime.mk Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/var.c diff -u src/usr.bin/make/var.c:1.1071 src/usr.bin/make/var.c:1.1072 --- src/usr.bin/make/var.c:1.1071 Sun Nov 19 11:30:28 2023 +++ src/usr.bin/make/var.c Sun Nov 19 11:47:49 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.1071 2023/11/19 11:30:28 rillig Exp $ */ +/* $NetBSD: var.c,v 1.1072 2023/11/19 11:47:49 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -139,7 +139,7 @@ #include "metachar.h" /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: var.c,v 1.1071 2023/11/19 11:30:28 rillig Exp $"); +MAKE_RCSID("$NetBSD: var.c,v 1.1072 2023/11/19 11:47:49 rillig Exp $"); /* * Variables are defined using one of the VAR=value assignments. Their @@ -2888,22 +2888,25 @@ ApplyModifier_Mtime(const char **pp, Mod if (args.use_fallback) { p++; if (TryParseTime(&p, &args.fallback)) { - } else if (strncmp(p, "error", 5) == 0 - && IsDelimiter(p[5], ch)) { + } else if (strncmp(p, "error", 5) == 0) { p += 5; args.error = true; - } else { - Parse_Error(PARSE_FATAL, - "Invalid argument '%.*s' for modifier ':mtime'", - (int)strcspn(p, ":{}()"), p); - return AMR_CLEANUP; - } + } else + goto invalid_argument; + if (!IsDelimiter(*p, ch)) + goto invalid_argument; *pp = p; } if (!ModChain_ShouldEval(ch)) return AMR_OK; ModifyWords(ch, ModifyWord_Mtime, &args, ch->oneBigWord); return args.rc; + +invalid_argument: + Parse_Error(PARSE_FATAL, + "Invalid argument '%.*s' for modifier ':mtime'", + (int)strcspn(*pp + 1, ":{}()"), *pp + 1); + return AMR_CLEANUP; } static void Index: src/usr.bin/make/unit-tests/varmod-mtime.exp diff -u src/usr.bin/make/unit-tests/varmod-mtime.exp:1.5 src/usr.bin/make/unit-tests/varmod-mtime.exp:1.6 --- src/usr.bin/make/unit-tests/varmod-mtime.exp:1.5 Sun Nov 19 11:37:44 2023 +++ src/usr.bin/make/unit-tests/varmod-mtime.exp Sun Nov 19 11:47:49 2023 @@ -1,4 +1,4 @@ -make: "varmod-mtime.mk" line 47: Unknown modifier "x" +make: "varmod-mtime.mk" line 47: Invalid argument '123x' for modifier ':mtime' make: "varmod-mtime.mk" line 47: Malformed conditional (${no/such/file:L:mtime=123x}) make: "varmod-mtime.mk" line 70: Cannot determine mtime for 'no/such/file1': <ENOENT> make: "varmod-mtime.mk" line 70: Cannot determine mtime for 'no/such/file2': <ENOENT> Index: src/usr.bin/make/unit-tests/varmod-mtime.mk diff -u src/usr.bin/make/unit-tests/varmod-mtime.mk:1.6 src/usr.bin/make/unit-tests/varmod-mtime.mk:1.7 --- src/usr.bin/make/unit-tests/varmod-mtime.mk:1.6 Sun Nov 19 11:37:44 2023 +++ src/usr.bin/make/unit-tests/varmod-mtime.mk Sun Nov 19 11:47:49 2023 @@ -1,4 +1,4 @@ -# $NetBSD: varmod-mtime.mk,v 1.6 2023/11/19 11:37:44 rillig Exp $ +# $NetBSD: varmod-mtime.mk,v 1.7 2023/11/19 11:47:49 rillig Exp $ # # Tests for the ':mtime' variable modifier, which maps each word of the # expression to that file's modification time. @@ -42,7 +42,7 @@ not_found_mtime:= ${no/such/file:L:mtime # The fallback timestamp must only be an integer, without trailing characters. -# expect+2: Unknown modifier "x" +# expect+2: Invalid argument '123x' for modifier ':mtime' # expect+1: Malformed conditional (${no/such/file:L:mtime=123x}) .if ${no/such/file:L:mtime=123x} . error