2011-06-16 Paul Eggert <eggert@cs.ucla.edu>
* editfns.c (Finsert_char): Don't dump core with very negative counts.
+ Tune. Don't use wider integers than needed. Don't use alloca.
+ Use a bigger 'string' buffer. Rewrite to avoid 'n > 0' test.
* insdel.c (replace_range): Fix buf overflow when insbytes < outgoing.
from adjoining text, if those properties are sticky. */)
(Lisp_Object character, Lisp_Object count, Lisp_Object inherit)
{
- register char *string;
- register EMACS_INT stringlen;
- register int i;
+ int i, stringlen;
register EMACS_INT n;
int c, len;
unsigned char str[MAX_MULTIBYTE_LENGTH];
+ char string[4000];
CHECK_CHARACTER (character);
CHECK_NUMBER (count);
if (BUF_BYTES_MAX / len < XINT (count))
buffer_overflow ();
n = XINT (count) * len;
- stringlen = min (n, 256 * len);
- string = (char *) alloca (stringlen);
+ stringlen = min (n, sizeof string - sizeof string % len);
for (i = 0; i < stringlen; i++)
string[i] = str[i % len];
- while (n >= stringlen)
+ while (n > stringlen)
{
QUIT;
if (!NILP (inherit))
insert (string, stringlen);
n -= stringlen;
}
- if (n > 0)
- {
- if (!NILP (inherit))
- insert_and_inherit (string, n);
- else
- insert (string, n);
- }
+ if (!NILP (inherit))
+ insert_and_inherit (string, n);
+ else
+ insert (string, n);
return Qnil;
}