diff options
| author | Paul Eggert | 2011-06-14 15:01:32 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-06-14 15:01:32 -0700 |
| commit | 00c604f263874880cc55a000af884c55743d6441 (patch) | |
| tree | f01e422ffd9a1cf764139f8fb568cfc90bd1c84c /src | |
| parent | dd0b0efbabfc187be6810a0e41b4ac5fdda667af (diff) | |
| download | emacs-00c604f263874880cc55a000af884c55743d6441.tar.gz emacs-00c604f263874880cc55a000af884c55743d6441.zip | |
* 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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 6 | ||||
| -rw-r--r-- | src/fns.c | 20 |
2 files changed, 16 insertions, 10 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index dd61843bc85..5d70c56cc5c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,11 @@ | |||
| 1 | 2011-06-14 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2011-06-14 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | * fns.c (Flength): Don't overflow int when computing a list length. | ||
| 4 | Use EMACS_INT, not int, to avoid unwanted truncation on 64-bit hosts. | ||
| 5 | Check for QUIT every 1024 entries rather than every other entry; | ||
| 6 | that's faster and is responsive enough. Report an error instead of | ||
| 7 | overflowing an integer. | ||
| 8 | |||
| 3 | * alloc.c: Check that resized vectors' lengths fit in fixnums. | 9 | * alloc.c: Check that resized vectors' lengths fit in fixnums. |
| 4 | (header_size, word_size): New constants. | 10 | (header_size, word_size): New constants. |
| 5 | (allocate_vectorlike): Don't check size overflow here. | 11 | (allocate_vectorlike): Don't check size overflow here. |
| @@ -110,7 +110,6 @@ To get the number of bytes, use `string-bytes'. */) | |||
| 110 | (register Lisp_Object sequence) | 110 | (register Lisp_Object sequence) |
| 111 | { | 111 | { |
| 112 | register Lisp_Object val; | 112 | register Lisp_Object val; |
| 113 | register int i; | ||
| 114 | 113 | ||
| 115 | if (STRINGP (sequence)) | 114 | if (STRINGP (sequence)) |
| 116 | XSETFASTINT (val, SCHARS (sequence)); | 115 | XSETFASTINT (val, SCHARS (sequence)); |
| @@ -124,19 +123,20 @@ To get the number of bytes, use `string-bytes'. */) | |||
| 124 | XSETFASTINT (val, ASIZE (sequence) & PSEUDOVECTOR_SIZE_MASK); | 123 | XSETFASTINT (val, ASIZE (sequence) & PSEUDOVECTOR_SIZE_MASK); |
| 125 | else if (CONSP (sequence)) | 124 | else if (CONSP (sequence)) |
| 126 | { | 125 | { |
| 127 | i = 0; | 126 | EMACS_INT i = 0; |
| 128 | while (CONSP (sequence)) | 127 | |
| 128 | do | ||
| 129 | { | 129 | { |
| 130 | sequence = XCDR (sequence); | ||
| 131 | ++i; | 130 | ++i; |
| 132 | 131 | if ((i & ((1 << 10) - 1)) == 0) | |
| 133 | if (!CONSP (sequence)) | 132 | { |
| 134 | break; | 133 | if (MOST_POSITIVE_FIXNUM < i) |
| 135 | 134 | error ("List too long"); | |
| 135 | QUIT; | ||
| 136 | } | ||
| 136 | sequence = XCDR (sequence); | 137 | sequence = XCDR (sequence); |
| 137 | ++i; | ||
| 138 | QUIT; | ||
| 139 | } | 138 | } |
| 139 | while (CONSP (sequence)); | ||
| 140 | 140 | ||
| 141 | CHECK_LIST_END (sequence, sequence); | 141 | CHECK_LIST_END (sequence, sequence); |
| 142 | 142 | ||