From 120f850dfec233b5f8f22212325520d500c5dcc3 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 16 Jul 2025 11:38:20 -0700 Subject: [PATCH] insert-file-contents small gap bug Problem reported by Zhengyi Fu (Bug#79031). * src/fileio.c (Finsert_file_contents): Do not read more than requested, even when the gap is so small that we use a local buffer. (cherry picked from commit e450a7802c544b7fa14fe064c62de1f9b7098e81) --- src/fileio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fileio.c b/src/fileio.c index 2c8855dba91..e33ac4afabf 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -4899,8 +4899,9 @@ by calling `format-decode', which see. */) else { buf = (char *) BEG_ADDR + PT_BYTE - BEG_BYTE + inserted; - bufsize = min (min (gap_size, total - inserted), IO_BUFSIZE); + bufsize = min (gap_size, IO_BUFSIZE); } + bufsize = min (bufsize, total - inserted); if (!seekable && end_offset == TYPE_MAXIMUM (off_t)) { -- 2.39.5