bugSCM Scheme Implementation - Bugs: bug #26779, Crashes with SEGFAULT on infinite...


bug #26779: Crashes with SEGFAULT on infinite recursion

Submitted by:  Danilo Piazzalunga <danilopiazza>
Submitted on:  Thu 11 Jun 2009 01:20:53 AM UTC  
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: None
Privacy: PublicAssigned to: Aubrey Jaffer <jaffer>
Open/Closed: Open

Add a New Comment(Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Thu 11 Jun 2009 08:05:20 PM UTC, comment #2:

It is ok if the interpreter throws an error, but it should not crash.

Danilo Piazzalunga <danilopiazza>
Thu 11 Jun 2009 07:35:23 PM UTC, comment #1:

If you run that code with -p3 or (verbose 3), then SCM gives a more informative error message (appended).

With -p3, the interpreter is checking the stack depth frequently; so it fails more quickly, even though the error that it happens to throw is still "segment violation".

scm -p3 -l overflow.scm
;loading overflow.scm
;; stack: 0xbfd1b498 - 0xbfd0b730; 64916 bytes

;ERROR: "overflow.scm": stack: segment violation
; in expression: (#@good-enough? #@guess #@x)
; in scope:
; (guess x) procedure sqrt-iter
; defined by load: "overflow.scm"

1; ((#@< (#@abs (#@- (#@square #@guess) #@x)) 1.0e-3))
2; ((#@new-if (#@good-enough? #@guess #@x) #@guess (#@sqrt-iter ( ...

; program args: ("scm" "-p3" "-l" "overflow.scm")
; shrank heap to 0 cells
; ;Totals: 0.ms my time, 20.ms your time

Aubrey Jaffer <jaffer>
Project AdministratorIn charge of this item.
Thu 11 Jun 2009 01:20:53 AM UTC, original submission:

Running the following code (taken from http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-10.html#%_thm_1.6), which results in an infinite recursion, makes the SCM interpreter seggault. Other Scheme interpreters, such as Guile and MIT-Scheme, will only abort with a "stack overflow" or "maximum recursion depth exceeded" error.

Using SCM 5e5 on Ubuntu 9.04 (i386).

(define (improve guess x)
(average guess (/ x guess)))

(define (average x y)
(/ (+ x y) 2))

(define (good-enough? guess x)
(< (abs (- (square guess) x)) 0.001))

(define (sqrt x)
(sqrt-iter 1.0 x))

(define (new-if predicate then-clause else-clause)
(cond (predicate then-clause)
(else else-clause)))

(define (sqrt-iter guess x)
(new-if (good-enough? guess x)
(sqrt-iter (improve guess x)

(define (square x) (* x x))

(sqrt 3)

Danilo Piazzalunga <danilopiazza>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -unavailable- added by jaffer (Posted a comment)
  • -unavailable- added by danilopiazza (Submitted the item)

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.


    Please enter the title of George Orwell's famous dystopian book (it's a date):



    Follows 1 latest change.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 11 Jun 2009 07:35:23 PM UTCjafferAssigned toNone=>jaffer

    Back to the top

    Powered by Savane 3.1-cleanup1