]> git.eshelyaron.com Git - emacs.git/commitdiff
insert-file-contents shrinking Solaris file fix
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 21 Jul 2025 21:56:43 +0000 (14:56 -0700)
committerEshel Yaron <me@eshelyaron.com>
Fri, 25 Jul 2025 08:11:52 +0000 (10:11 +0200)
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

index 2c60405ef35e2962fe04ffa2a601722524d08a27..7312efb624494d60ebfd8d73045d50153fd26c86 100644 (file)
@@ -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;
                    }
                }
            }