digego / extempore

A cyber-physical programming environment
1.41k stars 127 forks source link

Segfault in Scheme interpreter when calling subtract with a closure #306

Open amosr opened 6 years ago

amosr commented 6 years ago

Hi,

I found a case where trying to apply (-) to a closure produces a segfault. It's a silly program, but I did accidentally write it. I figure it should give a type error, not a segfault.

(define make-closure
  (lambda ()
    (let* ((offset 0)
           (beat-pos (lambda (x1) ())))
      (lambda () ()))))

(define closure (make-closure))
(- closure)

The fact that there is a let-bound closure variable referring to a lambda is interesting: it doesn't segfault if I change it to a number.

If I run the extempore in lldb, I get this information.

* thread #1, name = 'SP_task', queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x7fff5f3fff28)
    frame #0: 0x000000010000c9ee extempore`std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > std::__1::__pad_and_output<char, std::__1::char_traits<char> >(__s=ostreambuf_iterator<char, std::__1::char_traits<char> > @ 0x00007fff5f3fff28, __ob=<unavailable>, __op=<unavailable>, __oe=<unavailable>, __iob=<unavailable>, __fl=<unavailable>) at locale:1329
   1326 __pad_and_output(ostreambuf_iterator<_CharT, _Traits> __s,
   1327                  const _CharT* __ob, const _CharT* __op, const _CharT* __oe,
   1328                  ios_base& __iob, _CharT __fl)
-> 1329 {
   1330     if (__s.__sbuf_ == nullptr)
   1331         return __s;
   1332     streamsize __sz = __oe - __ob;

I can only guess, maybe it's printing the type error and doing something bad.

This is with master extempore on OSX.