diff options
| author | Mattias EngdegÄrd | 2022-08-31 14:31:31 +0200 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2022-09-01 10:11:53 +0200 |
| commit | e7193902b23deb842f55c1cd9100b807e199f4bd (patch) | |
| tree | afad58ebcd441b7ce52c418db25eb7e4d0145f4a /src | |
| parent | 941627f8d03ddf4cd0039902e494d0feabc88c85 (diff) | |
| download | emacs-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.c | 34 |
1 files changed, 20 insertions, 14 deletions
| @@ -1563,18 +1563,21 @@ If N is zero or negative, return nil. | |||
| 1563 | If N is greater or equal to the length of LIST, return LIST (or a copy). */) | 1563 | If 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. | |||
| 1602 | Otherwise, return LIST after truncating it. */) | 1605 | Otherwise, 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; |