Fix up length_internal with degenerate length inputs
* src/fns.c (length_internal): Protect against edge conditions.
This commit is contained in:
parent
80420faf49
commit
eb98afaf35
2 changed files with 16 additions and 2 deletions
|
@ -159,14 +159,14 @@ EMACS_INT length_internal (Lisp_Object sequence, int len)
|
|||
if (len < 0xffff)
|
||||
while (CONSP (sequence))
|
||||
{
|
||||
if (--len == 0)
|
||||
if (--len <= 0)
|
||||
return -1;
|
||||
sequence = XCDR (sequence);
|
||||
}
|
||||
/* Signal an error on circular lists. */
|
||||
else
|
||||
FOR_EACH_TAIL (sequence)
|
||||
if (--len == 0)
|
||||
if (--len <= 0)
|
||||
return -1;
|
||||
return len;
|
||||
}
|
||||
|
@ -210,6 +210,9 @@ counted. */)
|
|||
CHECK_FIXNUM (length);
|
||||
EMACS_INT len = XFIXNUM (length);
|
||||
|
||||
if (len < 0)
|
||||
return Qnil;
|
||||
|
||||
if (CONSP (sequence))
|
||||
return length_internal (sequence, len + 1) == 1? Qt: Qnil;
|
||||
else
|
||||
|
|
|
@ -1025,6 +1025,17 @@
|
|||
(should (length= "abc" 3))
|
||||
(should-not (length= "abc" 4))
|
||||
|
||||
(should-not (length< (list 1 2 3) -1))
|
||||
(should-not (length< (list 1 2 3) 0))
|
||||
(should-not (length< (list 1 2 3) -10))
|
||||
|
||||
(should (length> (list 1 2 3) -1))
|
||||
(should (length> (list 1 2 3) 0))
|
||||
|
||||
(should-not (length= (list 1 2 3) -1))
|
||||
(should-not (length= (list 1 2 3) 0))
|
||||
(should-not (length= (list 1 2 3) 1))
|
||||
|
||||
(should-error
|
||||
(let ((list (list 1)))
|
||||
(setcdr list list)
|
||||
|
|
Loading…
Add table
Reference in a new issue