aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKim F. Storm2004-06-21 21:54:30 +0000
committerKim F. Storm2004-06-21 21:54:30 +0000
commit7e2c051b993763cfae76e31b5887b81c303b4126 (patch)
tree263d330fa6bd0f187083961d458f3da676769f66 /src
parentf1a87317d2b28c75bdac503921615aab5ff7e5fe (diff)
downloademacs-7e2c051b993763cfae76e31b5887b81c303b4126.tar.gz
emacs-7e2c051b993763cfae76e31b5887b81c303b4126.zip
(Fformat, Ftranspose_regions): Use SAFE_ALLOCA.
Diffstat (limited to 'src')
-rw-r--r--src/editfns.c70
1 files changed, 29 insertions, 41 deletions
diff --git a/src/editfns.c b/src/editfns.c
index c9dd4ecefdf..9fbdc0363bb 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -3225,6 +3225,7 @@ usage: (format STRING &rest OBJECTS) */)
3225 int longest_format; 3225 int longest_format;
3226 Lisp_Object val; 3226 Lisp_Object val;
3227 int arg_intervals = 0; 3227 int arg_intervals = 0;
3228 USE_SAFE_ALLOCA;
3228 3229
3229 /* discarded[I] is 1 if byte I of the format 3230 /* discarded[I] is 1 if byte I of the format
3230 string was not copied into the output. 3231 string was not copied into the output.
@@ -3273,7 +3274,7 @@ usage: (format STRING &rest OBJECTS) */)
3273 longest_format = 0; 3274 longest_format = 0;
3274 3275
3275 /* Make room in result for all the non-%-codes in the control string. */ 3276 /* Make room in result for all the non-%-codes in the control string. */
3276 total = 5 + CONVERTED_BYTE_SIZE (multibyte, args[0]); 3277 total = 5 + CONVERTED_BYTE_SIZE (multibyte, args[0]) + 1;
3277 3278
3278 /* Allocate the info and discarded tables. */ 3279 /* Allocate the info and discarded tables. */
3279 { 3280 {
@@ -3466,10 +3467,7 @@ usage: (format STRING &rest OBJECTS) */)
3466 3467
3467 /* Allocate the space for the result. 3468 /* Allocate the space for the result.
3468 Note that TOTAL is an overestimate. */ 3469 Note that TOTAL is an overestimate. */
3469 if (total < 1000) 3470 SAFE_ALLOCA (buf, char *, total);
3470 buf = (char *) alloca (total + 1);
3471 else
3472 buf = (char *) xmalloc (total + 1);
3473 3471
3474 p = buf; 3472 p = buf;
3475 nchars = 0; 3473 nchars = 0;
@@ -3602,7 +3600,7 @@ usage: (format STRING &rest OBJECTS) */)
3602 maybe_combine_byte = 1; 3600 maybe_combine_byte = 1;
3603 this_nchars = strlen (p); 3601 this_nchars = strlen (p);
3604 if (multibyte) 3602 if (multibyte)
3605 p += str_to_multibyte (p, buf + total - p, this_nchars); 3603 p += str_to_multibyte (p, buf + total - 1 - p, this_nchars);
3606 else 3604 else
3607 p += this_nchars; 3605 p += this_nchars;
3608 nchars += this_nchars; 3606 nchars += this_nchars;
@@ -3639,7 +3637,7 @@ usage: (format STRING &rest OBJECTS) */)
3639 *p++ = *format++, nchars++; 3637 *p++ = *format++, nchars++;
3640 } 3638 }
3641 3639
3642 if (p > buf + total + 1) 3640 if (p > buf + total)
3643 abort (); 3641 abort ();
3644 3642
3645 if (maybe_combine_byte) 3643 if (maybe_combine_byte)
@@ -3647,8 +3645,7 @@ usage: (format STRING &rest OBJECTS) */)
3647 val = make_specified_string (buf, nchars, p - buf, multibyte); 3645 val = make_specified_string (buf, nchars, p - buf, multibyte);
3648 3646
3649 /* If we allocated BUF with malloc, free it too. */ 3647 /* If we allocated BUF with malloc, free it too. */
3650 if (total >= 1000) 3648 SAFE_FREE (total);
3651 xfree (buf);
3652 3649
3653 /* If the format string has text properties, or any of the string 3650 /* If the format string has text properties, or any of the string
3654 arguments has text properties, set up text properties of the 3651 arguments has text properties, set up text properties of the
@@ -4005,12 +4002,9 @@ Transposing beyond buffer boundaries is an error. */)
4005 /* First region smaller than second. */ 4002 /* First region smaller than second. */
4006 if (len1_byte < len2_byte) 4003 if (len1_byte < len2_byte)
4007 { 4004 {
4008 /* We use alloca only if it is small, 4005 USE_SAFE_ALLOCA;
4009 because we want to avoid stack overflow. */ 4006
4010 if (len2_byte > 20000) 4007 SAFE_ALLOCA (temp, unsigned char *, len2_byte);
4011 temp = (unsigned char *) xmalloc (len2_byte);
4012 else
4013 temp = (unsigned char *) alloca (len2_byte);
4014 4008
4015 /* Don't precompute these addresses. We have to compute them 4009 /* Don't precompute these addresses. We have to compute them
4016 at the last minute, because the relocating allocator might 4010 at the last minute, because the relocating allocator might
@@ -4021,23 +4015,20 @@ Transposing beyond buffer boundaries is an error. */)
4021 bcopy (start2_addr, temp, len2_byte); 4015 bcopy (start2_addr, temp, len2_byte);
4022 bcopy (start1_addr, start1_addr + len2_byte, len1_byte); 4016 bcopy (start1_addr, start1_addr + len2_byte, len1_byte);
4023 bcopy (temp, start1_addr, len2_byte); 4017 bcopy (temp, start1_addr, len2_byte);
4024 if (len2_byte > 20000) 4018 SAFE_FREE (len2_byte);
4025 xfree (temp);
4026 } 4019 }
4027 else 4020 else
4028 /* First region not smaller than second. */ 4021 /* First region not smaller than second. */
4029 { 4022 {
4030 if (len1_byte > 20000) 4023 USE_SAFE_ALLOCA;
4031 temp = (unsigned char *) xmalloc (len1_byte); 4024
4032 else 4025 SAFE_ALLOCA (temp, unsigned char *, len1_byte);
4033 temp = (unsigned char *) alloca (len1_byte);
4034 start1_addr = BYTE_POS_ADDR (start1_byte); 4026 start1_addr = BYTE_POS_ADDR (start1_byte);
4035 start2_addr = BYTE_POS_ADDR (start2_byte); 4027 start2_addr = BYTE_POS_ADDR (start2_byte);
4036 bcopy (start1_addr, temp, len1_byte); 4028 bcopy (start1_addr, temp, len1_byte);
4037 bcopy (start2_addr, start1_addr, len2_byte); 4029 bcopy (start2_addr, start1_addr, len2_byte);
4038 bcopy (temp, start1_addr + len2_byte, len1_byte); 4030 bcopy (temp, start1_addr + len2_byte, len1_byte);
4039 if (len1_byte > 20000) 4031 SAFE_FREE (len1_byte);
4040 xfree (temp);
4041 } 4032 }
4042 graft_intervals_into_buffer (tmp_interval1, start1 + len2, 4033 graft_intervals_into_buffer (tmp_interval1, start1 + len2,
4043 len1, current_buffer, 0); 4034 len1, current_buffer, 0);
@@ -4054,6 +4045,8 @@ Transposing beyond buffer boundaries is an error. */)
4054 if (len1_byte == len2_byte) 4045 if (len1_byte == len2_byte)
4055 /* Regions are same size, though, how nice. */ 4046 /* Regions are same size, though, how nice. */
4056 { 4047 {
4048 USE_SAFE_ALLOCA;
4049
4057 modify_region (current_buffer, start1, end1); 4050 modify_region (current_buffer, start1, end1);
4058 modify_region (current_buffer, start2, end2); 4051 modify_region (current_buffer, start2, end2);
4059 record_change (start1, len1); 4052 record_change (start1, len1);
@@ -4065,17 +4058,14 @@ Transposing beyond buffer boundaries is an error. */)
4065 Fset_text_properties (make_number (start2), make_number (end2), 4058 Fset_text_properties (make_number (start2), make_number (end2),
4066 Qnil, Qnil); 4059 Qnil, Qnil);
4067 4060
4068 if (len1_byte > 20000) 4061 SAFE_ALLOCA (temp, unsigned char *, len1_byte);
4069 temp = (unsigned char *) xmalloc (len1_byte);
4070 else
4071 temp = (unsigned char *) alloca (len1_byte);
4072 start1_addr = BYTE_POS_ADDR (start1_byte); 4062 start1_addr = BYTE_POS_ADDR (start1_byte);
4073 start2_addr = BYTE_POS_ADDR (start2_byte); 4063 start2_addr = BYTE_POS_ADDR (start2_byte);
4074 bcopy (start1_addr, temp, len1_byte); 4064 bcopy (start1_addr, temp, len1_byte);
4075 bcopy (start2_addr, start1_addr, len2_byte); 4065 bcopy (start2_addr, start1_addr, len2_byte);
4076 bcopy (temp, start2_addr, len1_byte); 4066 bcopy (temp, start2_addr, len1_byte);
4077 if (len1_byte > 20000) 4067 SAFE_FREE (len1_byte);
4078 xfree (temp); 4068
4079 graft_intervals_into_buffer (tmp_interval1, start2, 4069 graft_intervals_into_buffer (tmp_interval1, start2,
4080 len1, current_buffer, 0); 4070 len1, current_buffer, 0);
4081 graft_intervals_into_buffer (tmp_interval2, start1, 4071 graft_intervals_into_buffer (tmp_interval2, start1,
@@ -4085,6 +4075,8 @@ Transposing beyond buffer boundaries is an error. */)
4085 else if (len1_byte < len2_byte) /* Second region larger than first */ 4075 else if (len1_byte < len2_byte) /* Second region larger than first */
4086 /* Non-adjacent & unequal size, area between must also be shifted. */ 4076 /* Non-adjacent & unequal size, area between must also be shifted. */
4087 { 4077 {
4078 USE_SAFE_ALLOCA;
4079
4088 modify_region (current_buffer, start1, end2); 4080 modify_region (current_buffer, start1, end2);
4089 record_change (start1, (end2 - start1)); 4081 record_change (start1, (end2 - start1));
4090 tmp_interval1 = copy_intervals (cur_intv, start1, len1); 4082 tmp_interval1 = copy_intervals (cur_intv, start1, len1);
@@ -4094,18 +4086,15 @@ Transposing beyond buffer boundaries is an error. */)
4094 Qnil, Qnil); 4086 Qnil, Qnil);
4095 4087
4096 /* holds region 2 */ 4088 /* holds region 2 */
4097 if (len2_byte > 20000) 4089 SAFE_ALLOCA (temp, unsigned char *, len2_byte);
4098 temp = (unsigned char *) xmalloc (len2_byte);
4099 else
4100 temp = (unsigned char *) alloca (len2_byte);
4101 start1_addr = BYTE_POS_ADDR (start1_byte); 4090 start1_addr = BYTE_POS_ADDR (start1_byte);
4102 start2_addr = BYTE_POS_ADDR (start2_byte); 4091 start2_addr = BYTE_POS_ADDR (start2_byte);
4103 bcopy (start2_addr, temp, len2_byte); 4092 bcopy (start2_addr, temp, len2_byte);
4104 bcopy (start1_addr, start1_addr + len_mid + len2_byte, len1_byte); 4093 bcopy (start1_addr, start1_addr + len_mid + len2_byte, len1_byte);
4105 safe_bcopy (start1_addr + len1_byte, start1_addr + len2_byte, len_mid); 4094 safe_bcopy (start1_addr + len1_byte, start1_addr + len2_byte, len_mid);
4106 bcopy (temp, start1_addr, len2_byte); 4095 bcopy (temp, start1_addr, len2_byte);
4107 if (len2_byte > 20000) 4096 SAFE_FREE (len2_byte);
4108 xfree (temp); 4097
4109 graft_intervals_into_buffer (tmp_interval1, end2 - len1, 4098 graft_intervals_into_buffer (tmp_interval1, end2 - len1,
4110 len1, current_buffer, 0); 4099 len1, current_buffer, 0);
4111 graft_intervals_into_buffer (tmp_interval_mid, start1 + len2, 4100 graft_intervals_into_buffer (tmp_interval_mid, start1 + len2,
@@ -4116,6 +4105,8 @@ Transposing beyond buffer boundaries is an error. */)
4116 else 4105 else
4117 /* Second region smaller than first. */ 4106 /* Second region smaller than first. */
4118 { 4107 {
4108 USE_SAFE_ALLOCA;
4109
4119 record_change (start1, (end2 - start1)); 4110 record_change (start1, (end2 - start1));
4120 modify_region (current_buffer, start1, end2); 4111 modify_region (current_buffer, start1, end2);
4121 4112
@@ -4126,18 +4117,15 @@ Transposing beyond buffer boundaries is an error. */)
4126 Qnil, Qnil); 4117 Qnil, Qnil);
4127 4118
4128 /* holds region 1 */ 4119 /* holds region 1 */
4129 if (len1_byte > 20000) 4120 SAFE_ALLOCA (temp, unsigned char *, len1_byte);
4130 temp = (unsigned char *) xmalloc (len1_byte);
4131 else
4132 temp = (unsigned char *) alloca (len1_byte);
4133 start1_addr = BYTE_POS_ADDR (start1_byte); 4121 start1_addr = BYTE_POS_ADDR (start1_byte);
4134 start2_addr = BYTE_POS_ADDR (start2_byte); 4122 start2_addr = BYTE_POS_ADDR (start2_byte);
4135 bcopy (start1_addr, temp, len1_byte); 4123 bcopy (start1_addr, temp, len1_byte);
4136 bcopy (start2_addr, start1_addr, len2_byte); 4124 bcopy (start2_addr, start1_addr, len2_byte);
4137 bcopy (start1_addr + len1_byte, start1_addr + len2_byte, len_mid); 4125 bcopy (start1_addr + len1_byte, start1_addr + len2_byte, len_mid);
4138 bcopy (temp, start1_addr + len2_byte + len_mid, len1_byte); 4126 bcopy (temp, start1_addr + len2_byte + len_mid, len1_byte);
4139 if (len1_byte > 20000) 4127 SAFE_FREE (len1_byte);
4140 xfree (temp); 4128
4141 graft_intervals_into_buffer (tmp_interval1, end2 - len1, 4129 graft_intervals_into_buffer (tmp_interval1, end2 - len1,
4142 len1, current_buffer, 0); 4130 len1, current_buffer, 0);
4143 graft_intervals_into_buffer (tmp_interval_mid, start1 + len2, 4131 graft_intervals_into_buffer (tmp_interval_mid, start1 + len2,