2011-06-14 Paul Eggert <eggert@cs.ucla.edu>
+ * fns.c (Flength): Don't overflow int when computing a list length.
+ Use EMACS_INT, not int, to avoid unwanted truncation on 64-bit hosts.
+ Check for QUIT every 1024 entries rather than every other entry;
+ that's faster and is responsive enough. Report an error instead of
+ overflowing an integer.
+
* alloc.c: Check that resized vectors' lengths fit in fixnums.
(header_size, word_size): New constants.
(allocate_vectorlike): Don't check size overflow here.
(register Lisp_Object sequence)
{
register Lisp_Object val;
- register int i;
if (STRINGP (sequence))
XSETFASTINT (val, SCHARS (sequence));
XSETFASTINT (val, ASIZE (sequence) & PSEUDOVECTOR_SIZE_MASK);
else if (CONSP (sequence))
{
- i = 0;
- while (CONSP (sequence))
+ EMACS_INT i = 0;
+
+ do
{
- sequence = XCDR (sequence);
++i;
-
- if (!CONSP (sequence))
- break;
-
+ if ((i & ((1 << 10) - 1)) == 0)
+ {
+ if (MOST_POSITIVE_FIXNUM < i)
+ error ("List too long");
+ QUIT;
+ }
sequence = XCDR (sequence);
- ++i;
- QUIT;
}
+ while (CONSP (sequence));
CHECK_LIST_END (sequence, sequence);