aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2011-06-16 10:44:43 -0700
committerPaul Eggert2011-06-16 10:44:43 -0700
commit21d890a4ecf97141f3c3f7e373bca6d083662a83 (patch)
treecf72e75e1867e4da6da15e97d3555e55712c4624 /src
parent2e6813b0a503b14034783e12f704f7f70a47bae0 (diff)
downloademacs-21d890a4ecf97141f3c3f7e373bca6d083662a83.tar.gz
emacs-21d890a4ecf97141f3c3f7e373bca6d083662a83.zip
* editfns.c: Tune. Don't use wider integers than needed. Don't use alloca.
Use a bigger 'string' buffer. Rewrite to avoid 'n > 0' test.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog2
-rw-r--r--src/editfns.c21
2 files changed, 10 insertions, 13 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index d53817369c0..011f5beefe0 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,6 +1,8 @@
12011-06-16 Paul Eggert <eggert@cs.ucla.edu> 12011-06-16 Paul Eggert <eggert@cs.ucla.edu>
2 2
3 * editfns.c (Finsert_char): Don't dump core with very negative counts. 3 * editfns.c (Finsert_char): Don't dump core with very negative counts.
4 Tune. Don't use wider integers than needed. Don't use alloca.
5 Use a bigger 'string' buffer. Rewrite to avoid 'n > 0' test.
4 6
5 * insdel.c (replace_range): Fix buf overflow when insbytes < outgoing. 7 * insdel.c (replace_range): Fix buf overflow when insbytes < outgoing.
6 8
diff --git a/src/editfns.c b/src/editfns.c
index ab17eda86a9..2d736bbc7e2 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -2328,12 +2328,11 @@ The optional third arg INHERIT, if non-nil, says to inherit text properties
2328from adjoining text, if those properties are sticky. */) 2328from adjoining text, if those properties are sticky. */)
2329 (Lisp_Object character, Lisp_Object count, Lisp_Object inherit) 2329 (Lisp_Object character, Lisp_Object count, Lisp_Object inherit)
2330{ 2330{
2331 register char *string; 2331 int i, stringlen;
2332 register EMACS_INT stringlen;
2333 register int i;
2334 register EMACS_INT n; 2332 register EMACS_INT n;
2335 int c, len; 2333 int c, len;
2336 unsigned char str[MAX_MULTIBYTE_LENGTH]; 2334 unsigned char str[MAX_MULTIBYTE_LENGTH];
2335 char string[4000];
2337 2336
2338 CHECK_CHARACTER (character); 2337 CHECK_CHARACTER (character);
2339 CHECK_NUMBER (count); 2338 CHECK_NUMBER (count);
@@ -2348,11 +2347,10 @@ from adjoining text, if those properties are sticky. */)
2348 if (BUF_BYTES_MAX / len < XINT (count)) 2347 if (BUF_BYTES_MAX / len < XINT (count))
2349 buffer_overflow (); 2348 buffer_overflow ();
2350 n = XINT (count) * len; 2349 n = XINT (count) * len;
2351 stringlen = min (n, 256 * len); 2350 stringlen = min (n, sizeof string - sizeof string % len);
2352 string = (char *) alloca (stringlen);
2353 for (i = 0; i < stringlen; i++) 2351 for (i = 0; i < stringlen; i++)
2354 string[i] = str[i % len]; 2352 string[i] = str[i % len];
2355 while (n >= stringlen) 2353 while (n > stringlen)
2356 { 2354 {
2357 QUIT; 2355 QUIT;
2358 if (!NILP (inherit)) 2356 if (!NILP (inherit))
@@ -2361,13 +2359,10 @@ from adjoining text, if those properties are sticky. */)
2361 insert (string, stringlen); 2359 insert (string, stringlen);
2362 n -= stringlen; 2360 n -= stringlen;
2363 } 2361 }
2364 if (n > 0) 2362 if (!NILP (inherit))
2365 { 2363 insert_and_inherit (string, n);
2366 if (!NILP (inherit)) 2364 else
2367 insert_and_inherit (string, n); 2365 insert (string, n);
2368 else
2369 insert (string, n);
2370 }
2371 return Qnil; 2366 return Qnil;
2372} 2367}
2373 2368