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


bug #26779: Crashes with SEGFAULT on infinite recursion

Submitter:  Danilo Piazzalunga <danilopiazza>
Submitted:  Thu 11 Jun 2009 01:20:53 AM UTC
Category:  None Severity:  3 - Normal
Item Group:  None Status:  None
Privacy:  Public Assigned to:  jaffer
Open/Closed:  Open
* Mandatory Fields

Add a New Comment Rich Markup

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>
Group administrator
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 Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


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

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.


    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2009-06-11 jaffer Assigned toNone jaffer

    Back to the top

    Powered by Savane 3.13-1277.
    Corresponding source code