aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias EngdegÄrd2022-08-31 14:31:31 +0200
committerMattias EngdegÄrd2022-09-01 10:11:53 +0200
commite7193902b23deb842f55c1cd9100b807e199f4bd (patch)
treeafad58ebcd441b7ce52c418db25eb7e4d0145f4a /src
parent941627f8d03ddf4cd0039902e494d0feabc88c85 (diff)
downloademacs-e7193902b23deb842f55c1cd9100b807e199f4bd.tar.gz
emacs-e7193902b23deb842f55c1cd9100b807e199f4bd.zip
Better `take` and `ntake` bignum argument handling
* src/fns.c (Ftake, Fntake): Treat positive bignum arguments as most-positive-fixnum which results in better error checking of improper lists.
Diffstat (limited to 'src')
-rw-r--r--src/fns.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/fns.c b/src/fns.c
index 07102256fed..2f4808be3d0 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -1563,18 +1563,21 @@ If N is zero or negative, return nil.
1563If N is greater or equal to the length of LIST, return LIST (or a copy). */) 1563If N is greater or equal to the length of LIST, return LIST (or a copy). */)
1564 (Lisp_Object n, Lisp_Object list) 1564 (Lisp_Object n, Lisp_Object list)
1565{ 1565{
1566 if (BIGNUMP (n)) 1566 EMACS_INT m;
1567 if (FIXNUMP (n))
1568 {
1569 m = XFIXNUM (n);
1570 if (m <= 0)
1571 return Qnil;
1572 }
1573 else if (BIGNUMP (n))
1567 { 1574 {
1568 if (mpz_sgn (*xbignum_val (n)) < 0) 1575 if (mpz_sgn (*xbignum_val (n)) < 0)
1569 return Qnil; 1576 return Qnil;
1570 CHECK_LIST (list); 1577 m = MOST_POSITIVE_FIXNUM;
1571 return list;
1572 } 1578 }
1573 if (!FIXNUMP (n)) 1579 else
1574 wrong_type_argument (Qintegerp, n); 1580 wrong_type_argument (Qintegerp, n);
1575 EMACS_INT m = XFIXNUM (n);
1576 if (m <= 0)
1577 return Qnil;
1578 CHECK_LIST (list); 1581 CHECK_LIST (list);
1579 if (NILP (list)) 1582 if (NILP (list))
1580 return Qnil; 1583 return Qnil;
@@ -1602,18 +1605,21 @@ If N is greater or equal to the length of LIST, return LIST unmodified.
1602Otherwise, return LIST after truncating it. */) 1605Otherwise, return LIST after truncating it. */)
1603 (Lisp_Object n, Lisp_Object list) 1606 (Lisp_Object n, Lisp_Object list)
1604{ 1607{
1605 if (BIGNUMP (n)) 1608 EMACS_INT m;
1609 if (FIXNUMP (n))
1610 {
1611 m = XFIXNUM (n);
1612 if (m <= 0)
1613 return Qnil;
1614 }
1615 else if (BIGNUMP (n))
1606 { 1616 {
1607 if (mpz_sgn (*xbignum_val (n)) < 0) 1617 if (mpz_sgn (*xbignum_val (n)) < 0)
1608 return Qnil; 1618 return Qnil;
1609 CHECK_LIST (list); 1619 m = MOST_POSITIVE_FIXNUM;
1610 return list;
1611 } 1620 }
1612 if (!FIXNUMP (n)) 1621 else
1613 wrong_type_argument (Qintegerp, n); 1622 wrong_type_argument (Qintegerp, n);
1614 EMACS_INT m = XFIXNUM (n);
1615 if (m <= 0)
1616 return Qnil;
1617 CHECK_LIST (list); 1623 CHECK_LIST (list);
1618 Lisp_Object tail = list; 1624 Lisp_Object tail = list;
1619 --m; 1625 --m;