From: Philipp Stephani <p.stephani2@gmail.com>
To: 25477@debbugs.gnu.org
Subject: bug#25477: 26.0.50; `dolist' macro accepts more than three arguments
Date: Sun, 26 Mar 2017 18:56:39 +0000 [thread overview]
Message-ID: <CAArVCkTFvfZU32KXHPGi=JO8u7kR5uggddpUPRXMcGp14OcSSw@mail.gmail.com> (raw)
In-Reply-To: <wvr4lgu8dpam.fsf@gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 247 bytes --]
Philipp Stephani <p.stephani2@gmail.com> schrieb am Mi., 18. Jan. 2017 um
22:37 Uhr:
>
> In *scratch*, evaluate
>
> (dolist (a () 1 2 3))
>
> The result is 3, but a `wrong-number-of-arguments' signal should be
> raised.
>
I've attached a patch.
[-- Attachment #1.2: Type: text/html, Size: 675 bytes --]
[-- Attachment #2: 0001-Validate-SPEC-of-dolist-cf.-Bug-25477.txt --]
[-- Type: text/plain, Size: 1891 bytes --]
From cb1f8ce80edf1de7a1f9b886308a688a2ab6dcbf Mon Sep 17 00:00:00 2001
From: Philipp Stephani <phst@google.com>
Date: Sun, 26 Mar 2017 20:53:43 +0200
Subject: [PATCH] Validate SPEC of `dolist', cf. Bug#25477.
* lisp/subr.el (dolist): Test type and length of SPEC.
* test/lisp/subr-tests.el (subr-tests--dolist--wrong-number-of-args):
Add unit test.
---
lisp/subr.el | 4 ++++
test/lisp/subr-tests.el | 10 ++++++++++
2 files changed, 14 insertions(+)
diff --git a/lisp/subr.el b/lisp/subr.el
index 6b0403890c..65d1b9b482 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -190,6 +190,10 @@ dolist
\(fn (VAR LIST [RESULT]) BODY...)"
(declare (indent 1) (debug ((symbolp form &optional form) body)))
+ (unless (consp spec)
+ (signal 'wrong-type-argument (list 'consp spec)))
+ (unless (<= 2 (length spec) 3)
+ (signal 'wrong-number-of-arguments (list '(2 . 3) (length spec))))
;; It would be cleaner to create an uninterned symbol,
;; but that uses a lot more space when many functions in many files
;; use dolist.
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el
index a3b08e9697..0d243cc5d8 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -281,5 +281,15 @@ subr-test--frames-1
(should (equal (string-match-p "\\`[[:blank:]]\\'" "\u3000") 0))
(should-not (string-match-p "\\`[[:blank:]]\\'" "\N{LINE SEPARATOR}")))
+(ert-deftest subr-tests--dolist--wrong-number-of-args ()
+ "Test that `dolist' doesn't accept wrong types or length of SPEC,
+cf. Bug#25477."
+ (should-error (eval '(dolist (a)))
+ :type 'wrong-number-of-arguments)
+ (should-error (eval '(dolist (a () 'result 'invalid)) t)
+ :type 'wrong-number-of-arguments)
+ (should-error (eval '(dolist "foo") t)
+ :type 'wrong-type-argument))
+
(provide 'subr-tests)
;;; subr-tests.el ends here
--
2.12.2
next prev parent reply other threads:[~2017-03-26 18:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-18 21:35 bug#25477: 26.0.50; `dolist' macro accepts more than three arguments Philipp Stephani
2017-03-26 18:56 ` Philipp Stephani [this message]
2017-04-08 15:40 ` Philipp Stephani
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAArVCkTFvfZU32KXHPGi=JO8u7kR5uggddpUPRXMcGp14OcSSw@mail.gmail.com' \
--to=p.stephani2@gmail.com \
--cc=25477@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).