From: Paul Eggert Date: Mon, 21 Jul 2025 21:56:43 +0000 (-0700) Subject: insert-file-contents shrinking Solaris file fix X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=850c271a48a9227c3b743987b745bf46a232c966;p=emacs.git 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) --- 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; } } }