From 9956144405558933e130f39fb631b21985fba998 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 15 Jun 2011 23:48:01 -0700 Subject: [PATCH] * insdel.c, lisp.h (buffer_overflow): New function. (insert_from_buffer_1, replace_range, replace_range_2): * insdel.c (make_gap_larger): * editfns.c (Finsert_char): * fileio.c (Finsert_file_contents): Use it, to normalize wording. --- src/ChangeLog | 6 ++++++ src/editfns.c | 2 +- src/fileio.c | 4 ++-- src/insdel.c | 14 ++++++++++---- src/lisp.h | 1 + 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index ed94ce5599c..f7f18332288 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,11 @@ 2011-06-16 Paul Eggert + * insdel.c, lisp.h (buffer_overflow): New function. + (insert_from_buffer_1, replace_range, replace_range_2): + * insdel.c (make_gap_larger): + * editfns.c (Finsert_char): + * fileio.c (Finsert_file_contents): Use it, to normalize wording. + * buffer.h (BUF_BYTES_MAX): Cast to ptrdiff_t so that it's signed. 2011-06-15 Paul Eggert diff --git a/src/editfns.c b/src/editfns.c index 9678d4da6a2..dec0133951e 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -2344,7 +2344,7 @@ from adjoining text, if those properties are sticky. */) else str[0] = c, len = 1; if (BUF_BYTES_MAX / len < XINT (count)) - error ("Maximum buffer size would be exceeded"); + buffer_overflow (); n = XINT (count) * len; if (n <= 0) return Qnil; diff --git a/src/fileio.c b/src/fileio.c index fd5277cbd59..4458a3a4807 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -3264,7 +3264,7 @@ variable `last-coding-system-used' to the coding system actually used. */) platform that allows file sizes greater than the maximum off_t value. */ if (! not_regular && ! (0 <= st.st_size && st.st_size <= BUF_BYTES_MAX)) - error ("Maximum buffer size exceeded"); + buffer_overflow (); /* Prevent redisplay optimizations. */ current_buffer->clip_changed = 1; @@ -3808,7 +3808,7 @@ variable `last-coding-system-used' to the coding system actually used. */) /* Make sure point-max won't overflow after this insertion. */ XSETINT (temp, total); if (total != XINT (temp)) - error ("Maximum buffer size exceeded"); + buffer_overflow (); } else /* For a special file, all we can do is guess. */ diff --git a/src/insdel.c b/src/insdel.c index c0cccc65d6a..875274df8e4 100644 --- a/src/insdel.c +++ b/src/insdel.c @@ -391,6 +391,12 @@ adjust_markers_for_replace (EMACS_INT from, EMACS_INT from_byte, } +void +buffer_overflow (void) +{ + error ("Maximum buffer size exceeded"); +} + /* Make the gap NBYTES_ADDED bytes longer. */ static void @@ -408,7 +414,7 @@ make_gap_larger (EMACS_INT nbytes_added) if (total_size < 0 /* Don't allow a buffer size that won't fit in a Lisp integer. */ || total_size != XINT (make_number (total_size))) - error ("Buffer exceeds maximum size"); + buffer_overflow (); } enlarge_buffer_text (current_buffer, nbytes_added); @@ -1105,7 +1111,7 @@ insert_from_buffer_1 (struct buffer *buf, /* Make sure point-max won't overflow after this insertion. */ XSETINT (temp, outgoing_nbytes + Z); if (outgoing_nbytes + Z != XINT (temp)) - error ("Maximum buffer size exceeded"); + buffer_overflow (); /* Do this before moving and increasing the gap, because the before-change hooks might move the gap @@ -1350,7 +1356,7 @@ replace_range (EMACS_INT from, EMACS_INT to, Lisp_Object new, /* Make sure point-max won't overflow after this insertion. */ XSETINT (temp, Z_BYTE - nbytes_del + insbytes); if (Z_BYTE - nbytes_del + insbytes != XINT (temp)) - error ("Maximum buffer size exceeded"); + buffer_overflow (); GCPRO1 (new); @@ -1495,7 +1501,7 @@ replace_range_2 (EMACS_INT from, EMACS_INT from_byte, /* Make sure point-max won't overflow after this insertion. */ XSETINT (temp, Z_BYTE - nbytes_del + insbytes); if (Z_BYTE - nbytes_del + insbytes != XINT (temp)) - error ("Maximum buffer size exceeded"); + buffer_overflow (); /* Make sure the gap is somewhere in or next to what we are deleting. */ if (from > GPT) diff --git a/src/lisp.h b/src/lisp.h index 83534e55433..75827deda1a 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -2635,6 +2635,7 @@ extern void init_image (void); extern Lisp_Object Qinhibit_modification_hooks; extern void move_gap (EMACS_INT); extern void move_gap_both (EMACS_INT, EMACS_INT); +extern void buffer_overflow (void) NO_RETURN; extern void make_gap (EMACS_INT); extern EMACS_INT copy_text (const unsigned char *, unsigned char *, EMACS_INT, int, int); -- 2.11.4.GIT