Steel Bank Common Lisp

null &REST args broken

Reported by Alex Plotnick on 2013-03-14
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
SBCL
High
Unassigned

Bug Description

The "funky &REST smartness" introduced in commit 373df66df093e8c1771069dcc30c2ec32598af6a is apparently not quite smart enough; on SBCL 1.0.58.51-373df66 and newer:

(funcall (lambda (&rest args) (car args)) 1)
1
* (funcall (lambda (&rest args) (car args)))
34368823132

Evaluating the second form on the previous commit (ef0891e) yields the correct result (NIL). And it's not just lambdas that are affected.

This is on a FreeBSD 9.0 amd64 system.

Paul Khuong (pvk) wrote :

The &more magic doesn't check bounds. I'd assign it to myself, but I'm really not sure I'll find the time this weekend.

Changed in sbcl:
importance: Undecided → High
status: New → Triaged
Stas Boukarev (stassats) wrote :

I've committed a simple (< (the index n) count) as a fix, more clever optimizations (if there are) could be done later.

Stas Boukarev (stassats) wrote :

commit fa2e7181b3f21505a340ae25a5f41998f67665a8
Author: Stas Boukarev <email address hidden>
Date: Thu Mar 14 14:09:54 2013 +0400

    Accessing &MORE arguments checks bounds.

    (funcall (lambda (&rest args) (car args))) => garbage,
    because &more accessing didn't check bounds.

Stas Boukarev (stassats) on 2013-03-14
Changed in sbcl:
status: Triaged → Fix Committed
nixie (onixie) wrote :

Bug #1072112 is also fixed, I think.

Stas Boukarev (stassats) on 2013-03-31
Changed in sbcl:
status: Fix Committed → Fix Released

Is the bug related to this behaviour?

  (funcall (lambda (&rest args) (elt args 0))) => NIL

I think that the function elt should signal a type-error when index is out of bounds, as it is in the previous example.

Thanks in advance.
Rafael.

Stas Boukarev (stassats) wrote :

Yes, it's somewhat related. Although it doesn't signal any errors in the following case either:

(funcall (lambda (args) (elt (the list args) 0)) ())

only in
(funcall (lambda (args) (declare (optimize safety)) (elt (the list args) 0)) ())

Stas Boukarev (stassats) wrote :

I fixed that by disabling this ELT optimization when safety = 3.

I have read the Hyperspec and it says "Should signal an error of type type-error if index is not a valid sequence index for sequence". Then, I understand that "should" is not mandatory.

Thank you very much.

Stas Boukarev (stassats) wrote :

With the fix i committed, it signals an error. But only in safe code (see http://www.lispworks.com/reference/HyperSpec/Body/03_eaa.htm), the same as in the regular ELT on lists. Now the question whether elt should signal errors with safety = 1 is for another bug report/wishlist.

Perfect. Thanks again.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers