diff options
| author | Paul Eggert | 2019-01-31 10:29:50 -0800 |
|---|---|---|
| committer | Paul Eggert | 2019-01-31 10:31:43 -0800 |
| commit | 05d2fc7170fb66a87601b1c76ddae2c1b7b4b934 (patch) | |
| tree | 217ddd3a45ea611069d85ac13e22e525bb965996 /src/buffer.c | |
| parent | a68eee50eb515b28b448894299334afced26ef78 (diff) | |
| download | emacs-05d2fc7170fb66a87601b1c76ddae2c1b7b4b934.tar.gz emacs-05d2fc7170fb66a87601b1c76ddae2c1b7b4b934.zip | |
Widen modiff counts to avoid wraparound
Widen modification counts to at least 64 bits, to make
wraparound practically impossible.
* doc/lispref/buffers.texi (Buffer Modification):
Don’t say the modification-count can wrap around.
* src/buffer.c (Frestore_buffer_modified_p, Fbuffer_swap_text)
(modify_overlay):
* src/insdel.c (insert_1_both, insert_from_string_1)
(insert_from_gap, insert_from_buffer_1)
(adjust_after_replace, replace_range, replace_range_2)
(del_range_2, modify_text):
* src/textprop.c (modify_text_properties):
Use modiff_incr instead of incrementing directly.
(Fbuffer_modified_tick, Fbuffer_chars_modified_tick):
Don’t assume modification counts fit into fixnums.
* src/buffer.h (struct buffer_text, struct buffer):
* src/cmds.c (internal_self_insert):
* src/fileio.c (Finsert_file_contents):
* src/indent.c (last_known_column_modified):
* src/keyboard.c (command_loop_1):
* src/marker.c (cached_modiff):
* src/syntax.c (find_start_modiff, parse_sexp_propertize)
(find_defun_start):
* src/window.h (struct window):
Use modiff_count for modification counts.
* src/editfns.c (Fsubst_char_in_region):
Copy instead of incrementing modification counts,
since integer overflow checking is not needed here.
* src/lisp.h (modiff_count): New type.
(modiff_incr, modiff_to_integer): New inline functions.
* src/pdumper.c (dump_buffer): Update hash.
Diffstat (limited to 'src/buffer.c')
| -rw-r--r-- | src/buffer.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/buffer.c b/src/buffer.c index a12c80ec0b0..e5cc5f367f0 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -1413,7 +1413,7 @@ state of the current buffer. Use with care. */) | |||
| 1413 | /* If SAVE_MODIFF == auto_save_modified == MODIFF, | 1413 | /* If SAVE_MODIFF == auto_save_modified == MODIFF, |
| 1414 | we can either decrease SAVE_MODIFF and auto_save_modified | 1414 | we can either decrease SAVE_MODIFF and auto_save_modified |
| 1415 | or increase MODIFF. */ | 1415 | or increase MODIFF. */ |
| 1416 | : MODIFF++); | 1416 | : modiff_incr (&MODIFF)); |
| 1417 | 1417 | ||
| 1418 | return flag; | 1418 | return flag; |
| 1419 | } | 1419 | } |
| @@ -1422,11 +1422,11 @@ DEFUN ("buffer-modified-tick", Fbuffer_modified_tick, Sbuffer_modified_tick, | |||
| 1422 | 0, 1, 0, | 1422 | 0, 1, 0, |
| 1423 | doc: /* Return BUFFER's tick counter, incremented for each change in text. | 1423 | doc: /* Return BUFFER's tick counter, incremented for each change in text. |
| 1424 | Each buffer has a tick counter which is incremented each time the | 1424 | Each buffer has a tick counter which is incremented each time the |
| 1425 | text in that buffer is changed. It wraps around occasionally. | 1425 | text in that buffer is changed. No argument or nil as argument means |
| 1426 | No argument or nil as argument means use current buffer as BUFFER. */) | 1426 | use current buffer as BUFFER. */) |
| 1427 | (register Lisp_Object buffer) | 1427 | (Lisp_Object buffer) |
| 1428 | { | 1428 | { |
| 1429 | return make_fixnum (BUF_MODIFF (decode_buffer (buffer))); | 1429 | return modiff_to_integer (BUF_MODIFF (decode_buffer (buffer))); |
| 1430 | } | 1430 | } |
| 1431 | 1431 | ||
| 1432 | DEFUN ("buffer-chars-modified-tick", Fbuffer_chars_modified_tick, | 1432 | DEFUN ("buffer-chars-modified-tick", Fbuffer_chars_modified_tick, |
| @@ -1439,9 +1439,9 @@ values returned by two individual calls of `buffer-chars-modified-tick', | |||
| 1439 | you can tell whether a character change occurred in that buffer in | 1439 | you can tell whether a character change occurred in that buffer in |
| 1440 | between these calls. No argument or nil as argument means use current | 1440 | between these calls. No argument or nil as argument means use current |
| 1441 | buffer as BUFFER. */) | 1441 | buffer as BUFFER. */) |
| 1442 | (register Lisp_Object buffer) | 1442 | (Lisp_Object buffer) |
| 1443 | { | 1443 | { |
| 1444 | return make_fixnum (BUF_CHARS_MODIFF (decode_buffer (buffer))); | 1444 | return modiff_to_integer (BUF_CHARS_MODIFF (decode_buffer (buffer))); |
| 1445 | } | 1445 | } |
| 1446 | 1446 | ||
| 1447 | DEFUN ("rename-buffer", Frename_buffer, Srename_buffer, 1, 2, | 1447 | DEFUN ("rename-buffer", Frename_buffer, Srename_buffer, 1, 2, |
| @@ -2375,9 +2375,12 @@ results, see Info node `(elisp)Swapping Text'. */) | |||
| 2375 | bset_point_before_scroll (current_buffer, Qnil); | 2375 | bset_point_before_scroll (current_buffer, Qnil); |
| 2376 | bset_point_before_scroll (other_buffer, Qnil); | 2376 | bset_point_before_scroll (other_buffer, Qnil); |
| 2377 | 2377 | ||
| 2378 | current_buffer->text->modiff++; other_buffer->text->modiff++; | 2378 | modiff_incr (¤t_buffer->text->modiff); |
| 2379 | current_buffer->text->chars_modiff++; other_buffer->text->chars_modiff++; | 2379 | modiff_incr (&other_buffer->text->modiff); |
| 2380 | current_buffer->text->overlay_modiff++; other_buffer->text->overlay_modiff++; | 2380 | modiff_incr (¤t_buffer->text->chars_modiff); |
| 2381 | modiff_incr (&other_buffer->text->chars_modiff); | ||
| 2382 | modiff_incr (¤t_buffer->text->overlay_modiff); | ||
| 2383 | modiff_incr (&other_buffer->text->overlay_modiff); | ||
| 2381 | current_buffer->text->beg_unchanged = current_buffer->text->gpt; | 2384 | current_buffer->text->beg_unchanged = current_buffer->text->gpt; |
| 2382 | current_buffer->text->end_unchanged = current_buffer->text->gpt; | 2385 | current_buffer->text->end_unchanged = current_buffer->text->gpt; |
| 2383 | other_buffer->text->beg_unchanged = other_buffer->text->gpt; | 2386 | other_buffer->text->beg_unchanged = other_buffer->text->gpt; |
| @@ -3913,7 +3916,7 @@ modify_overlay (struct buffer *buf, ptrdiff_t start, ptrdiff_t end) | |||
| 3913 | 3916 | ||
| 3914 | bset_redisplay (buf); | 3917 | bset_redisplay (buf); |
| 3915 | 3918 | ||
| 3916 | ++BUF_OVERLAY_MODIFF (buf); | 3919 | modiff_incr (&BUF_OVERLAY_MODIFF (buf)); |
| 3917 | } | 3920 | } |
| 3918 | 3921 | ||
| 3919 | /* Remove OVERLAY from LIST. */ | 3922 | /* Remove OVERLAY from LIST. */ |