aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2023-02-12 17:30:46 -0800
committerPaul Eggert2023-02-13 12:32:58 -0800
commit5284af27ee5250c631ff4ee2f3d8682f0c5df8bc (patch)
tree80b740d59de499d8fdbcb1ee50df71471aee8f2a /src
parentdf5c1c9370ca3c6a6e119278ef6bb1e3bca4d578 (diff)
downloademacs-5284af27ee5250c631ff4ee2f3d8682f0c5df8bc.tar.gz
emacs-5284af27ee5250c631ff4ee2f3d8682f0c5df8bc.zip
Improve insert-file-contents checking
* src/fileio.c (Finsert_file_contents): Check BEG, END, REPLACE for validity before launching into opening files etc.
Diffstat (limited to 'src')
-rw-r--r--src/fileio.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/src/fileio.c b/src/fileio.c
index c672e0f7baf..64337abdaef 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -3908,7 +3908,6 @@ by calling `format-decode', which see. */)
3908 int fd; 3908 int fd;
3909 ptrdiff_t inserted = 0; 3909 ptrdiff_t inserted = 0;
3910 ptrdiff_t how_much; 3910 ptrdiff_t how_much;
3911 off_t beg_offset, end_offset;
3912 int unprocessed; 3911 int unprocessed;
3913 specpdl_ref count = SPECPDL_INDEX (); 3912 specpdl_ref count = SPECPDL_INDEX ();
3914 Lisp_Object handler, val, insval, orig_filename, old_undo; 3913 Lisp_Object handler, val, insval, orig_filename, old_undo;
@@ -3970,6 +3969,17 @@ by calling `format-decode', which see. */)
3970 goto handled; 3969 goto handled;
3971 } 3970 }
3972 3971
3972 if (!NILP (visit))
3973 {
3974 if (!NILP (beg) || !NILP (end))
3975 error ("Attempt to visit less than an entire file");
3976 if (BEG < Z && NILP (replace))
3977 error ("Cannot do file visiting in a non-empty buffer");
3978 }
3979
3980 off_t beg_offset = !NILP (beg) ? file_offset (beg) : 0;
3981 off_t end_offset = !NILP (end) ? file_offset (end) : -1;
3982
3973 orig_filename = filename; 3983 orig_filename = filename;
3974 filename = ENCODE_FILE (filename); 3984 filename = ENCODE_FILE (filename);
3975 3985
@@ -4030,22 +4040,7 @@ by calling `format-decode', which see. */)
4030 build_string ("not a regular file"), orig_filename); 4040 build_string ("not a regular file"), orig_filename);
4031 } 4041 }
4032 4042
4033 if (!NILP (visit)) 4043 if (end_offset < 0)
4034 {
4035 if (!NILP (beg) || !NILP (end))
4036 error ("Attempt to visit less than an entire file");
4037 if (BEG < Z && NILP (replace))
4038 error ("Cannot do file visiting in a non-empty buffer");
4039 }
4040
4041 if (!NILP (beg))
4042 beg_offset = file_offset (beg);
4043 else
4044 beg_offset = 0;
4045
4046 if (!NILP (end))
4047 end_offset = file_offset (end);
4048 else
4049 { 4044 {
4050 if (!regular) 4045 if (!regular)
4051 end_offset = TYPE_MAXIMUM (off_t); 4046 end_offset = TYPE_MAXIMUM (off_t);