On 1/19/22 15:28, Paul Eggert wrote:

Proposed patch attached.

I see that patch's commit message has the wrong URL for the bug report. Here's a fixed patch, attached. Only the commit message is changed.
From 1b9f1bb7f95699e9c0d59b177e83c1b3bc3852a0 Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Wed, 19 Jan 2022 15:20:40 -0800
Subject: [PATCH] Fix interleaved $(info) output
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* src/function.c (func_error): On POSIX-compatible platforms,
cause $(info xxx) output to a pipe to be atomic when xxx is small,
the same way that $(warning xxx) and $(error xxx) is.  Problem
reported by Lars Ingebrigtsen <https://bugs.gnu.org/53358>.
Also, shrink allocation by 1 byte (the byte isn’t ever used)
and avoid an unnecessary initialization of msg[0].
---
 src/function.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/function.c b/src/function.c
index c107a387..05c77c32 100644
--- a/src/function.c
+++ b/src/function.c
@@ -1180,17 +1180,16 @@ func_error (char *o, char **argv, const char *funcname)
   for (len=0, argvp=argv; *argvp != 0; ++argvp)
     len += strlen (*argvp) + 2;
 
-  p = msg = alloca (len + 1);
-  msg[0] = '\0';
+  p = msg = alloca (len);
 
-  for (argvp=argv; argvp[1] != 0; ++argvp)
+  for (argvp=argv; *argvp != 0; ++argvp)
     {
       strcpy (p, *argvp);
       p += strlen (*argvp);
       *(p++) = ',';
       *(p++) = ' ';
     }
-  strcpy (p, *argvp);
+  p[-2] = '\0';
 
   switch (*funcname)
     {
@@ -1202,8 +1201,8 @@ func_error (char *o, char **argv, const char *funcname)
       break;
 
     case 'i':
+      strcpy (p - 2, "\n");
       outputs (0, msg);
-      outputs (0, "\n");
       break;
 
     default:
-- 
2.32.0

Reply via email to