summaryrefslogtreecommitdiff
path: root/src/fileio.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2023-02-12 17:30:46 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2023-02-13 12:32:58 -0800
commit5284af27ee5250c631ff4ee2f3d8682f0c5df8bc (patch)
tree80b740d59de499d8fdbcb1ee50df71471aee8f2a /src/fileio.c
parentdf5c1c9370ca3c6a6e119278ef6bb1e3bca4d578 (diff)
downloademacs-5284af27ee5250c631ff4ee2f3d8682f0c5df8bc.tar.gz
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/fileio.c')
-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. */)
int fd;
ptrdiff_t inserted = 0;
ptrdiff_t how_much;
- off_t beg_offset, end_offset;
int unprocessed;
specpdl_ref count = SPECPDL_INDEX ();
Lisp_Object handler, val, insval, orig_filename, old_undo;
@@ -3970,6 +3969,17 @@ by calling `format-decode', which see. */)
goto handled;
}
+ if (!NILP (visit))
+ {
+ if (!NILP (beg) || !NILP (end))
+ error ("Attempt to visit less than an entire file");
+ if (BEG < Z && NILP (replace))
+ error ("Cannot do file visiting in a non-empty buffer");
+ }
+
+ off_t beg_offset = !NILP (beg) ? file_offset (beg) : 0;
+ off_t end_offset = !NILP (end) ? file_offset (end) : -1;
+
orig_filename = filename;
filename = ENCODE_FILE (filename);
@@ -4030,22 +4040,7 @@ by calling `format-decode', which see. */)
build_string ("not a regular file"), orig_filename);
}
- if (!NILP (visit))
- {
- if (!NILP (beg) || !NILP (end))
- error ("Attempt to visit less than an entire file");
- if (BEG < Z && NILP (replace))
- error ("Cannot do file visiting in a non-empty buffer");
- }
-
- if (!NILP (beg))
- beg_offset = file_offset (beg);
- else
- beg_offset = 0;
-
- if (!NILP (end))
- end_offset = file_offset (end);
- else
+ if (end_offset < 0)
{
if (!regular)
end_offset = TYPE_MAXIMUM (off_t);