From 850c271a48a9227c3b743987b745bf46a232c966 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 21 Jul 2025 14:56:43 -0700 Subject: [PATCH] insert-file-contents shrinking Solaris file fix This is related to recent fixes for Bug#77315. * src/fileio.c (Finsert_file_contents): Defend against a file shrinking to be smaller than its initial offset. This can happen only on platforms like Solaris where the initial offset can be positive. (cherry picked from commit 8393e469e7f1771b4e167392eef169ab51c047b2) --- src/fileio.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/fileio.c b/src/fileio.c index 2c60405ef35..7312efb6244 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -4529,8 +4529,9 @@ by calling `format-decode', which see. */) { /* Shrink the file's head if the file shrank to be smaller than its head. */ - if (endpos - beg_offset < same_at_start - BEGV_BYTE) - same_at_start = endpos - beg_offset + BEGV_BYTE; + off_t offset_from_beg = endpos - beg_offset; + if (offset_from_beg < same_at_start - BEGV_BYTE) + same_at_start = max (0, offset_from_beg) + BEGV_BYTE; } } } -- 2.39.5