aboutsummaryrefslogtreecommitdiffstats
path: root/src/editfns.c
diff options
context:
space:
mode:
authorMiles Bader2004-06-29 16:46:06 +0000
committerMiles Bader2004-06-29 16:46:06 +0000
commit12483a9413619e286efc673a2b277d85cebf3b0c (patch)
treed489e0fa758c0d51d792d42140cbeafa4aede31b /src/editfns.c
parentc786a8ae1c5e84d0f0903d516dd0fc190dc1193c (diff)
parent619b6adbd2b96accbbf18051bf69149a029557ee (diff)
downloademacs-12483a9413619e286efc673a2b277d85cebf3b0c.tar.gz
emacs-12483a9413619e286efc673a2b277d85cebf3b0c.zip
Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-17
Merge from emacs--cvs-trunk--0 Patches applied: * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-417 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-419 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-420 Tweak permissions * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-421 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-430 Update from CVS
Diffstat (limited to 'src/editfns.c')
-rw-r--r--src/editfns.c70
1 files changed, 29 insertions, 41 deletions
diff --git a/src/editfns.c b/src/editfns.c
index 130dffa77de..9928beff678 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -3381,6 +3381,7 @@ usage: (format STRING &rest OBJECTS) */)
3381 int longest_format; 3381 int longest_format;
3382 Lisp_Object val; 3382 Lisp_Object val;
3383 int arg_intervals = 0; 3383 int arg_intervals = 0;
3384 USE_SAFE_ALLOCA;
3384 3385
3385 /* discarded[I] is 1 if byte I of the format 3386 /* discarded[I] is 1 if byte I of the format
3386 string was not copied into the output. 3387 string was not copied into the output.
@@ -3429,7 +3430,7 @@ usage: (format STRING &rest OBJECTS) */)
3429 longest_format = 0; 3430 longest_format = 0;
3430 3431
3431 /* Make room in result for all the non-%-codes in the control string. */ 3432 /* Make room in result for all the non-%-codes in the control string. */
3432 total = 5 + CONVERTED_BYTE_SIZE (multibyte, args[0]); 3433 total = 5 + CONVERTED_BYTE_SIZE (multibyte, args[0]) + 1;
3433 3434
3434 /* Allocate the info and discarded tables. */ 3435 /* Allocate the info and discarded tables. */
3435 { 3436 {
@@ -3622,10 +3623,7 @@ usage: (format STRING &rest OBJECTS) */)
3622 3623
3623 /* Allocate the space for the result. 3624 /* Allocate the space for the result.
3624 Note that TOTAL is an overestimate. */ 3625 Note that TOTAL is an overestimate. */
3625 if (total < 1000) 3626 SAFE_ALLOCA (buf, char *, total);
3626 buf = (char *) alloca (total + 1);
3627 else
3628 buf = (char *) xmalloc (total + 1);
3629 3627
3630 p = buf; 3628 p = buf;
3631 nchars = 0; 3629 nchars = 0;
@@ -3758,7 +3756,7 @@ usage: (format STRING &rest OBJECTS) */)
3758 maybe_combine_byte = 1; 3756 maybe_combine_byte = 1;
3759 this_nchars = strlen (p); 3757 this_nchars = strlen (p);
3760 if (multibyte) 3758 if (multibyte)
3761 p += str_to_multibyte (p, buf + total - p, this_nchars); 3759 p += str_to_multibyte (p, buf + total - 1 - p, this_nchars);
3762 else 3760 else
3763 p += this_nchars; 3761 p += this_nchars;
3764 nchars += this_nchars; 3762 nchars += this_nchars;
@@ -3795,7 +3793,7 @@ usage: (format STRING &rest OBJECTS) */)
3795 *p++ = *format++, nchars++; 3793 *p++ = *format++, nchars++;
3796 } 3794 }
3797 3795
3798 if (p > buf + total + 1) 3796 if (p > buf + total)
3799 abort (); 3797 abort ();
3800 3798
3801 if (maybe_combine_byte) 3799 if (maybe_combine_byte)
@@ -3803,8 +3801,7 @@ usage: (format STRING &rest OBJECTS) */)
3803 val = make_specified_string (buf, nchars, p - buf, multibyte); 3801 val = make_specified_string (buf, nchars, p - buf, multibyte);
3804 3802
3805 /* If we allocated BUF with malloc, free it too. */ 3803 /* If we allocated BUF with malloc, free it too. */
3806 if (total >= 1000) 3804 SAFE_FREE (total);
3807 xfree (buf);
3808 3805
3809 /* If the format string has text properties, or any of the string 3806 /* If the format string has text properties, or any of the string
3810 arguments has text properties, set up text properties of the 3807 arguments has text properties, set up text properties of the
@@ -4173,12 +4170,9 @@ Transposing beyond buffer boundaries is an error. */)
4173 /* First region smaller than second. */ 4170 /* First region smaller than second. */
4174 if (len1_byte < len2_byte) 4171 if (len1_byte < len2_byte)
4175 { 4172 {
4176 /* We use alloca only if it is small, 4173 USE_SAFE_ALLOCA;
4177 because we want to avoid stack overflow. */ 4174
4178 if (len2_byte > 20000) 4175 SAFE_ALLOCA (temp, unsigned char *, len2_byte);
4179 temp = (unsigned char *) xmalloc (len2_byte);
4180 else
4181 temp = (unsigned char *) alloca (len2_byte);
4182 4176
4183 /* Don't precompute these addresses. We have to compute them 4177 /* Don't precompute these addresses. We have to compute them
4184 at the last minute, because the relocating allocator might 4178 at the last minute, because the relocating allocator might
@@ -4189,23 +4183,20 @@ Transposing beyond buffer boundaries is an error. */)
4189 bcopy (start2_addr, temp, len2_byte); 4183 bcopy (start2_addr, temp, len2_byte);
4190 bcopy (start1_addr, start1_addr + len2_byte, len1_byte); 4184 bcopy (start1_addr, start1_addr + len2_byte, len1_byte);
4191 bcopy (temp, start1_addr, len2_byte); 4185 bcopy (temp, start1_addr, len2_byte);
4192 if (len2_byte > 20000) 4186 SAFE_FREE (len2_byte);
4193 xfree (temp);
4194 } 4187 }
4195 else 4188 else
4196 /* First region not smaller than second. */ 4189 /* First region not smaller than second. */
4197 { 4190 {
4198 if (len1_byte > 20000) 4191 USE_SAFE_ALLOCA;
4199 temp = (unsigned char *) xmalloc (len1_byte); 4192
4200 else 4193 SAFE_ALLOCA (temp, unsigned char *, len1_byte);
4201 temp = (unsigned char *) alloca (len1_byte);
4202 start1_addr = BYTE_POS_ADDR (start1_byte); 4194 start1_addr = BYTE_POS_ADDR (start1_byte);
4203 start2_addr = BYTE_POS_ADDR (start2_byte); 4195 start2_addr = BYTE_POS_ADDR (start2_byte);
4204 bcopy (start1_addr, temp, len1_byte); 4196 bcopy (start1_addr, temp, len1_byte);
4205 bcopy (start2_addr, start1_addr, len2_byte); 4197 bcopy (start2_addr, start1_addr, len2_byte);
4206 bcopy (temp, start1_addr + len2_byte, len1_byte); 4198 bcopy (temp, start1_addr + len2_byte, len1_byte);
4207 if (len1_byte > 20000) 4199 SAFE_FREE (len1_byte);
4208 xfree (temp);
4209 } 4200 }
4210 graft_intervals_into_buffer (tmp_interval1, start1 + len2, 4201 graft_intervals_into_buffer (tmp_interval1, start1 + len2,
4211 len1, current_buffer, 0); 4202 len1, current_buffer, 0);
@@ -4222,6 +4213,8 @@ Transposing beyond buffer boundaries is an error. */)
4222 if (len1_byte == len2_byte) 4213 if (len1_byte == len2_byte)
4223 /* Regions are same size, though, how nice. */ 4214 /* Regions are same size, though, how nice. */
4224 { 4215 {
4216 USE_SAFE_ALLOCA;
4217
4225 modify_region (current_buffer, start1, end1); 4218 modify_region (current_buffer, start1, end1);
4226 modify_region (current_buffer, start2, end2); 4219 modify_region (current_buffer, start2, end2);
4227 record_change (start1, len1); 4220 record_change (start1, len1);
@@ -4233,17 +4226,14 @@ Transposing beyond buffer boundaries is an error. */)
4233 Fset_text_properties (make_number (start2), make_number (end2), 4226 Fset_text_properties (make_number (start2), make_number (end2),
4234 Qnil, Qnil); 4227 Qnil, Qnil);
4235 4228
4236 if (len1_byte > 20000) 4229 SAFE_ALLOCA (temp, unsigned char *, len1_byte);
4237 temp = (unsigned char *) xmalloc (len1_byte);
4238 else
4239 temp = (unsigned char *) alloca (len1_byte);
4240 start1_addr = BYTE_POS_ADDR (start1_byte); 4230 start1_addr = BYTE_POS_ADDR (start1_byte);
4241 start2_addr = BYTE_POS_ADDR (start2_byte); 4231 start2_addr = BYTE_POS_ADDR (start2_byte);
4242 bcopy (start1_addr, temp, len1_byte); 4232 bcopy (start1_addr, temp, len1_byte);
4243 bcopy (start2_addr, start1_addr, len2_byte); 4233 bcopy (start2_addr, start1_addr, len2_byte);
4244 bcopy (temp, start2_addr, len1_byte); 4234 bcopy (temp, start2_addr, len1_byte);
4245 if (len1_byte > 20000) 4235 SAFE_FREE (len1_byte);
4246 xfree (temp); 4236
4247 graft_intervals_into_buffer (tmp_interval1, start2, 4237 graft_intervals_into_buffer (tmp_interval1, start2,
4248 len1, current_buffer, 0); 4238 len1, current_buffer, 0);
4249 graft_intervals_into_buffer (tmp_interval2, start1, 4239 graft_intervals_into_buffer (tmp_interval2, start1,
@@ -4253,6 +4243,8 @@ Transposing beyond buffer boundaries is an error. */)
4253 else if (len1_byte < len2_byte) /* Second region larger than first */ 4243 else if (len1_byte < len2_byte) /* Second region larger than first */
4254 /* Non-adjacent & unequal size, area between must also be shifted. */ 4244 /* Non-adjacent & unequal size, area between must also be shifted. */
4255 { 4245 {
4246 USE_SAFE_ALLOCA;
4247
4256 modify_region (current_buffer, start1, end2); 4248 modify_region (current_buffer, start1, end2);
4257 record_change (start1, (end2 - start1)); 4249 record_change (start1, (end2 - start1));
4258 tmp_interval1 = copy_intervals (cur_intv, start1, len1); 4250 tmp_interval1 = copy_intervals (cur_intv, start1, len1);
@@ -4262,18 +4254,15 @@ Transposing beyond buffer boundaries is an error. */)
4262 Qnil, Qnil); 4254 Qnil, Qnil);
4263 4255
4264 /* holds region 2 */ 4256 /* holds region 2 */
4265 if (len2_byte > 20000) 4257 SAFE_ALLOCA (temp, unsigned char *, len2_byte);
4266 temp = (unsigned char *) xmalloc (len2_byte);
4267 else
4268 temp = (unsigned char *) alloca (len2_byte);
4269 start1_addr = BYTE_POS_ADDR (start1_byte); 4258 start1_addr = BYTE_POS_ADDR (start1_byte);
4270 start2_addr = BYTE_POS_ADDR (start2_byte); 4259 start2_addr = BYTE_POS_ADDR (start2_byte);
4271 bcopy (start2_addr, temp, len2_byte); 4260 bcopy (start2_addr, temp, len2_byte);
4272 bcopy (start1_addr, start1_addr + len_mid + len2_byte, len1_byte); 4261 bcopy (start1_addr, start1_addr + len_mid + len2_byte, len1_byte);
4273 safe_bcopy (start1_addr + len1_byte, start1_addr + len2_byte, len_mid); 4262 safe_bcopy (start1_addr + len1_byte, start1_addr + len2_byte, len_mid);
4274 bcopy (temp, start1_addr, len2_byte); 4263 bcopy (temp, start1_addr, len2_byte);
4275 if (len2_byte > 20000) 4264 SAFE_FREE (len2_byte);
4276 xfree (temp); 4265
4277 graft_intervals_into_buffer (tmp_interval1, end2 - len1, 4266 graft_intervals_into_buffer (tmp_interval1, end2 - len1,
4278 len1, current_buffer, 0); 4267 len1, current_buffer, 0);
4279 graft_intervals_into_buffer (tmp_interval_mid, start1 + len2, 4268 graft_intervals_into_buffer (tmp_interval_mid, start1 + len2,
@@ -4284,6 +4273,8 @@ Transposing beyond buffer boundaries is an error. */)
4284 else 4273 else
4285 /* Second region smaller than first. */ 4274 /* Second region smaller than first. */
4286 { 4275 {
4276 USE_SAFE_ALLOCA;
4277
4287 record_change (start1, (end2 - start1)); 4278 record_change (start1, (end2 - start1));
4288 modify_region (current_buffer, start1, end2); 4279 modify_region (current_buffer, start1, end2);
4289 4280
@@ -4294,18 +4285,15 @@ Transposing beyond buffer boundaries is an error. */)
4294 Qnil, Qnil); 4285 Qnil, Qnil);
4295 4286
4296 /* holds region 1 */ 4287 /* holds region 1 */
4297 if (len1_byte > 20000) 4288 SAFE_ALLOCA (temp, unsigned char *, len1_byte);
4298 temp = (unsigned char *) xmalloc (len1_byte);
4299 else
4300 temp = (unsigned char *) alloca (len1_byte);
4301 start1_addr = BYTE_POS_ADDR (start1_byte); 4289 start1_addr = BYTE_POS_ADDR (start1_byte);
4302 start2_addr = BYTE_POS_ADDR (start2_byte); 4290 start2_addr = BYTE_POS_ADDR (start2_byte);
4303 bcopy (start1_addr, temp, len1_byte); 4291 bcopy (start1_addr, temp, len1_byte);
4304 bcopy (start2_addr, start1_addr, len2_byte); 4292 bcopy (start2_addr, start1_addr, len2_byte);
4305 bcopy (start1_addr + len1_byte, start1_addr + len2_byte, len_mid); 4293 bcopy (start1_addr + len1_byte, start1_addr + len2_byte, len_mid);
4306 bcopy (temp, start1_addr + len2_byte + len_mid, len1_byte); 4294 bcopy (temp, start1_addr + len2_byte + len_mid, len1_byte);
4307 if (len1_byte > 20000) 4295 SAFE_FREE (len1_byte);
4308 xfree (temp); 4296
4309 graft_intervals_into_buffer (tmp_interval1, end2 - len1, 4297 graft_intervals_into_buffer (tmp_interval1, end2 - len1,
4310 len1, current_buffer, 0); 4298 len1, current_buffer, 0);
4311 graft_intervals_into_buffer (tmp_interval_mid, start1 + len2, 4299 graft_intervals_into_buffer (tmp_interval_mid, start1 + len2,