From: Paul Eggert Date: Sat, 13 Jul 2019 19:31:41 +0000 (-0700) Subject: Use a better buffer size in emacs_perror X-Git-Tag: emacs-27.0.90~1935 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=9a34591ddd5ef481af5bad1fd0b76c39fce4e8e3;p=emacs.git 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. --- 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 */