From 9a34591ddd5ef481af5bad1fd0b76c39fce4e8e3 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 13 Jul 2019 12:31:41 -0700 Subject: [PATCH] Use a better buffer size in emacs_perror * src/sysdep.c (emacs_perror): Since the buffer is for avoiding interleaving, size it via PIPE_BUF not BUFSIZ. * src/sysstdio.h (PIPE_BUF): Provide a default. --- src/sysdep.c | 4 ++-- src/sysstdio.h | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/sysdep.c b/src/sysdep.c index 4c3d546962c..9301405943b 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -2711,10 +2711,10 @@ emacs_perror (char const *message) ? initial_argv[0] : "emacs"); /* Write it out all at once, if it's short; this is less likely to be interleaved with other output. */ - char buf[BUFSIZ]; + char buf[min (PIPE_BUF, MAX_ALLOCA)]; int nbytes = snprintf (buf, sizeof buf, "%s: %s: %s\n", command, message, error_string); - if (0 <= nbytes && nbytes < BUFSIZ) + if (0 <= nbytes && nbytes < sizeof buf) emacs_write (STDERR_FILENO, buf, nbytes); else { diff --git a/src/sysstdio.h b/src/sysstdio.h index 5303e8a15b2..637f5fdfa6d 100644 --- a/src/sysstdio.h +++ b/src/sysstdio.h @@ -21,6 +21,7 @@ along with GNU Emacs. If not, see . */ #define EMACS_SYSSTDIO_H #include +#include #include #include "unlocked-io.h" @@ -38,4 +39,8 @@ extern void close_output_streams (void); # define FOPEN_TEXT "" #endif +#ifndef PIPE_BUF + #define PIPE_BUF MAX_ALLOCA +#endif + #endif /* EMACS_SYSSTDIO_H */ -- 2.39.2