aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c101
1 files changed, 36 insertions, 65 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 45d6fa36d04..37d2975c8c7 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1698,27 +1698,16 @@ record_buffer (Lisp_Object buffer)
1698 call1 (Vrun_hooks, Qbuffer_list_update_hook); 1698 call1 (Vrun_hooks, Qbuffer_list_update_hook);
1699} 1699}
1700 1700
1701DEFUN ("record-buffer", Frecord_buffer, Srecord_buffer, 1, 1, 0,
1702 doc: /* Move BUFFER to the front of the buffer list.
1703Return BUFFER. */)
1704 (Lisp_Object buffer)
1705{
1706 CHECK_BUFFER (buffer);
1707
1708 record_buffer (buffer);
1709
1710 return buffer;
1711}
1712 1701
1713 /* Move BUFFER to the end of the buffer (a)lists. Do nothing if the 1702/* Move BUFFER to the end of the buffer (a)lists. Do nothing if the
1714 buffer is killed. For the selected frame's buffer list this moves 1703 buffer is killed. For the selected frame's buffer list this moves
1715 BUFFER to its end even if it was never shown in that frame. If 1704 BUFFER to its end even if it was never shown in that frame. If
1716 this happens we have a feature, hence `unrecord-buffer' should be 1705 this happens we have a feature, hence `unrecord-buffer' should be
1717 called only when BUFFER was shown in the selected frame. */ 1706 called only when BUFFER was shown in the selected frame. */
1718 1707
1719DEFUN ("unrecord-buffer", Funrecord_buffer, Sunrecord_buffer, 1, 1, 0, 1708DEFUN ("bury-buffer-internal", Fbury_buffer_internal, Sbury_buffer_internal,
1720 doc: /* Move BUFFER to the end of the buffer list. 1709 1, 1, 0,
1721Return BUFFER. */) 1710 doc: /* Move BUFFER to the end of the buffer list. */)
1722 (Lisp_Object buffer) 1711 (Lisp_Object buffer)
1723{ 1712{
1724 Lisp_Object aelt, aelt_cons, tem; 1713 Lisp_Object aelt, aelt_cons, tem;
@@ -1746,7 +1735,7 @@ Return BUFFER. */)
1746 if (!NILP (Vrun_hooks)) 1735 if (!NILP (Vrun_hooks))
1747 call1 (Vrun_hooks, Qbuffer_list_update_hook); 1736 call1 (Vrun_hooks, Qbuffer_list_update_hook);
1748 1737
1749 return buffer; 1738 return Qnil;
1750} 1739}
1751 1740
1752DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode, Sset_buffer_major_mode, 1, 1, 0, 1741DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode, Sset_buffer_major_mode, 1, 1, 0,
@@ -2568,13 +2557,10 @@ overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr,
2568 Either make it bigger, or don't store any more in it. */ 2557 Either make it bigger, or don't store any more in it. */
2569 if (extend) 2558 if (extend)
2570 { 2559 {
2571 if ((OVERLAY_COUNT_MAX - 4) / 2 < len) 2560 vec = xpalloc (vec, len_ptr, 1, OVERLAY_COUNT_MAX,
2572 memory_full (SIZE_MAX); 2561 sizeof *vec);
2573 /* Make it work with an initial len == 0. */
2574 len = len * 2 + 4;
2575 *len_ptr = len;
2576 vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object));
2577 *vec_ptr = vec; 2562 *vec_ptr = vec;
2563 len = *len_ptr;
2578 } 2564 }
2579 else 2565 else
2580 inhibit_storing = 1; 2566 inhibit_storing = 1;
@@ -2611,13 +2597,10 @@ overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr,
2611 { 2597 {
2612 if (extend) 2598 if (extend)
2613 { 2599 {
2614 if ((OVERLAY_COUNT_MAX - 4) / 2 < len) 2600 vec = xpalloc (vec, len_ptr, 1, OVERLAY_COUNT_MAX,
2615 memory_full (SIZE_MAX); 2601 sizeof *vec);
2616 /* Make it work with an initial len == 0. */
2617 len = len * 2 + 4;
2618 *len_ptr = len;
2619 vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object));
2620 *vec_ptr = vec; 2602 *vec_ptr = vec;
2603 len = *len_ptr;
2621 } 2604 }
2622 else 2605 else
2623 inhibit_storing = 1; 2606 inhibit_storing = 1;
@@ -2708,13 +2691,10 @@ overlays_in (EMACS_INT beg, EMACS_INT end, int extend,
2708 Either make it bigger, or don't store any more in it. */ 2691 Either make it bigger, or don't store any more in it. */
2709 if (extend) 2692 if (extend)
2710 { 2693 {
2711 if ((OVERLAY_COUNT_MAX - 4) / 2 < len) 2694 vec = xpalloc (vec, len_ptr, 1, OVERLAY_COUNT_MAX,
2712 memory_full (SIZE_MAX); 2695 sizeof *vec);
2713 /* Make it work with an initial len == 0. */
2714 len = len * 2 + 4;
2715 *len_ptr = len;
2716 vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object));
2717 *vec_ptr = vec; 2696 *vec_ptr = vec;
2697 len = *len_ptr;
2718 } 2698 }
2719 else 2699 else
2720 inhibit_storing = 1; 2700 inhibit_storing = 1;
@@ -2756,13 +2736,10 @@ overlays_in (EMACS_INT beg, EMACS_INT end, int extend,
2756 { 2736 {
2757 if (extend) 2737 if (extend)
2758 { 2738 {
2759 if ((OVERLAY_COUNT_MAX - 4) / 2 < len) 2739 vec = xpalloc (vec, len_ptr, 1, OVERLAY_COUNT_MAX,
2760 memory_full (SIZE_MAX); 2740 sizeof *vec);
2761 /* Make it work with an initial len == 0. */
2762 len = len * 2 + 4;
2763 *len_ptr = len;
2764 vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object));
2765 *vec_ptr = vec; 2741 *vec_ptr = vec;
2742 len = *len_ptr;
2766 } 2743 }
2767 else 2744 else
2768 inhibit_storing = 1; 2745 inhibit_storing = 1;
@@ -2944,7 +2921,7 @@ struct sortstrlist
2944 struct sortstr *buf; /* An array that expands as needed; never freed. */ 2921 struct sortstr *buf; /* An array that expands as needed; never freed. */
2945 ptrdiff_t size; /* Allocated length of that array. */ 2922 ptrdiff_t size; /* Allocated length of that array. */
2946 ptrdiff_t used; /* How much of the array is currently in use. */ 2923 ptrdiff_t used; /* How much of the array is currently in use. */
2947 EMACS_INT bytes; /* Total length of the strings in buf. */ 2924 ptrdiff_t bytes; /* Total length of the strings in buf. */
2948}; 2925};
2949 2926
2950/* Buffers for storing information about the overlays touching a given 2927/* Buffers for storing information about the overlays touching a given
@@ -2955,7 +2932,7 @@ static struct sortstrlist overlay_heads, overlay_tails;
2955static unsigned char *overlay_str_buf; 2932static unsigned char *overlay_str_buf;
2956 2933
2957/* Allocated length of overlay_str_buf. */ 2934/* Allocated length of overlay_str_buf. */
2958static EMACS_INT overlay_str_len; 2935static ptrdiff_t overlay_str_len;
2959 2936
2960/* A comparison function suitable for passing to qsort. */ 2937/* A comparison function suitable for passing to qsort. */
2961static int 2938static int
@@ -2977,17 +2954,7 @@ record_overlay_string (struct sortstrlist *ssl, Lisp_Object str,
2977 EMACS_INT nbytes; 2954 EMACS_INT nbytes;
2978 2955
2979 if (ssl->used == ssl->size) 2956 if (ssl->used == ssl->size)
2980 { 2957 ssl->buf = xpalloc (ssl->buf, &ssl->size, 5, -1, sizeof *ssl->buf);
2981 if (min (PTRDIFF_MAX, SIZE_MAX) / (sizeof (struct sortstr) * 2)
2982 < ssl->size)
2983 memory_full (SIZE_MAX);
2984 else if (0 < ssl->size)
2985 ssl->size *= 2;
2986 else
2987 ssl->size = 5;
2988 ssl->buf = ((struct sortstr *)
2989 xrealloc (ssl->buf, ssl->size * sizeof (struct sortstr)));
2990 }
2991 ssl->buf[ssl->used].string = str; 2958 ssl->buf[ssl->used].string = str;
2992 ssl->buf[ssl->used].string2 = str2; 2959 ssl->buf[ssl->used].string2 = str2;
2993 ssl->buf[ssl->used].size = size; 2960 ssl->buf[ssl->used].size = size;
@@ -3002,6 +2969,8 @@ record_overlay_string (struct sortstrlist *ssl, Lisp_Object str,
3002 else 2969 else
3003 nbytes = SBYTES (str); 2970 nbytes = SBYTES (str);
3004 2971
2972 if (INT_ADD_OVERFLOW (ssl->bytes, nbytes))
2973 memory_full (SIZE_MAX);
3005 ssl->bytes += nbytes; 2974 ssl->bytes += nbytes;
3006 2975
3007 if (STRINGP (str2)) 2976 if (STRINGP (str2))
@@ -3014,6 +2983,8 @@ record_overlay_string (struct sortstrlist *ssl, Lisp_Object str,
3014 else 2983 else
3015 nbytes = SBYTES (str2); 2984 nbytes = SBYTES (str2);
3016 2985
2986 if (INT_ADD_OVERFLOW (ssl->bytes, nbytes))
2987 memory_full (SIZE_MAX);
3017 ssl->bytes += nbytes; 2988 ssl->bytes += nbytes;
3018 } 2989 }
3019} 2990}
@@ -3107,14 +3078,15 @@ overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr)
3107 Lisp_Object tem; 3078 Lisp_Object tem;
3108 EMACS_INT i; 3079 EMACS_INT i;
3109 unsigned char *p; 3080 unsigned char *p;
3110 EMACS_INT total = overlay_heads.bytes + overlay_tails.bytes; 3081 ptrdiff_t total;
3111 3082
3083 if (INT_ADD_OVERFLOW (overlay_heads.bytes, overlay_tails.bytes))
3084 memory_full (SIZE_MAX);
3085 total = overlay_heads.bytes + overlay_tails.bytes;
3112 if (total > overlay_str_len) 3086 if (total > overlay_str_len)
3113 { 3087 overlay_str_buf = xpalloc (overlay_str_buf, &overlay_str_len,
3114 overlay_str_len = total; 3088 total - overlay_str_len, -1, 1);
3115 overlay_str_buf = (unsigned char *)xrealloc (overlay_str_buf, 3089
3116 total);
3117 }
3118 p = overlay_str_buf; 3090 p = overlay_str_buf;
3119 for (i = overlay_tails.used; --i >= 0;) 3091 for (i = overlay_tails.used; --i >= 0;)
3120 { 3092 {
@@ -6034,8 +6006,7 @@ Functions running this hook are `get-buffer-create',
6034 defsubr (&Sother_buffer); 6006 defsubr (&Sother_buffer);
6035 defsubr (&Sbuffer_enable_undo); 6007 defsubr (&Sbuffer_enable_undo);
6036 defsubr (&Skill_buffer); 6008 defsubr (&Skill_buffer);
6037 defsubr (&Srecord_buffer); 6009 defsubr (&Sbury_buffer_internal);
6038 defsubr (&Sunrecord_buffer);
6039 defsubr (&Sset_buffer_major_mode); 6010 defsubr (&Sset_buffer_major_mode);
6040 defsubr (&Scurrent_buffer); 6011 defsubr (&Scurrent_buffer);
6041 defsubr (&Sset_buffer); 6012 defsubr (&Sset_buffer);