From 5f2d114c6d7d896f3bb604e12798372e3fc3e43b Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Wed, 19 Jan 2022 15:49:19 -0800 Subject: [PATCH] Avoid interleaved $(info ) output Since $(info ) function output is written using two system calls for the message and the newline, it's possible for output from another parallel make job to sneak in between them. Reported by Paul Eggert , who saw the report from Lars Ingebrigtsen . * src/function.c (func_error): Paul provided a fix but instead I rewrote the entire function: it's not possible for it to be invoked with anything other than exactly one argument so don't worry about re-combining the arguments. --- src/function.c | 38 +++++++++++--------------------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/src/function.c b/src/function.c index c27f573b..d7c13923 100644 --- a/src/function.c +++ b/src/function.c @@ -1171,41 +1171,25 @@ func_strip (char *o, char **argv, const char *funcname UNUSED) static char * func_error (char *o, char **argv, const char *funcname) { - char **argvp; - char *msg, *p; - size_t len; - - /* The arguments will be broken on commas. Rather than create yet - another special case where function arguments aren't broken up, - just create a format string that puts them back together. */ - for (len=0, argvp=argv; *argvp != 0; ++argvp) - len += strlen (*argvp) + 2; - - p = msg = alloca (len + 1); - msg[0] = '\0'; - - for (argvp=argv; argvp[1] != 0; ++argvp) - { - strcpy (p, *argvp); - p += strlen (*argvp); - *(p++) = ','; - *(p++) = ' '; - } - strcpy (p, *argvp); - switch (*funcname) { case 'e': - OS (fatal, reading_file, "%s", msg); + OS (fatal, reading_file, "%s", argv[0]); case 'w': - OS (error, reading_file, "%s", msg); + OS (error, reading_file, "%s", argv[0]); break; case 'i': - outputs (0, msg); - outputs (0, "\n"); - break; + { + size_t len = strlen (argv[0]); + char *msg = alloca (len + 2); + strcpy (msg, argv[0]); + msg[len] = '\n'; + msg[len + 1] = '\0'; + outputs (0, msg); + break; + } default: OS (fatal, *expanding_var, "Internal error: func_error: '%s'", funcname);