# Bug: segfault when using super and method\_missing

**URL:** <https://www.ruby-forum.com/t/bug-segfault-when-using-super-and-method-missing/55699>\
**Category:** Ruby\
**Created:** [March 23, 2006, 2:09am UTC](https://www.ruby-forum.com/t/bug-segfault-when-using-super-and-method-missing/55699 "2006-03-23T02:09:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhutchins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f1d935/32.png) [@bhutchins](https://www.ruby-forum.com/u/bhutchins)\
**Post date:** [March 23, 2006, 2:09am UTC](https://www.ruby-forum.com/t/bug-segfault-when-using-super-and-method-missing/55699/1 "2006-03-23T02:09:44Z")

</div>

Hello,

The following code produces a segfault with ruby-1.8.4 from gentoo,  
as well as with ruby-1.8 from cvs and 1.9 from cvs. There appears to  
be an issue when super is called in the subclass and the parent class  
has method\_missing defined. Strangely, if super is called with  
explicit arguments, no segfault occurs. Likewise, if the method  
definition in the subclass is modified slightly (see below) the  
segfault is avoided.

Thanks,  
Brad

* * *

class BaseClass  
def method\_missing(\*args)  
p args  
end  
end

class Article \< BaseClass

# if this is defined as title=(arg) the segfault does not occur

def title=(\*args)  
super(args) # works  
super(\*args) # works  
super # segfault…  
end  
end

a = Article.new  
a.body = ‘body’  
a.title = ‘foo’

---

<div class="post-metadata">

**Author:** ![bhutchins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f1d935/32.png) [@bhutchins](https://www.ruby-forum.com/u/bhutchins)\
**Post date:** [March 23, 2006, 2:29am UTC](https://www.ruby-forum.com/t/bug-segfault-when-using-super-and-method-missing/55699/2 "2006-03-23T02:29:46Z")

</div>

Hi,

This works for me. I’ve tried both:

ruby 1.8.2 (2004-12-25) [i386-mswin32] (Windows)  
ruby 1.8.4 (2005-12-24) [i386-linux] (gentoo linux)

Just a guess, but maybe you compiled ruby with to much optimizations in  
CFLAGS ? Mine are

CFLAGS="-O2 -fomit-frame-pointer"

Hope this helps…

Guillaume

---

<div class="post-metadata">

**Author:** ![bhutchins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f1d935/32.png) [@bhutchins](https://www.ruby-forum.com/u/bhutchins)\
**Post date:** [March 23, 2006, 2:49am UTC](https://www.ruby-forum.com/t/bug-segfault-when-using-super-and-method-missing/55699/3 "2006-03-23T02:49:59Z")

</div>

Hi,

In message “Re: bug: segfault when using super and method\_missing”  
on Thu, 23 Mar 2006 10:09:37 +0900, Brad H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
writes:

|The following code produces a segfault with ruby-1.8.4 from gentoo,  
|as well as with ruby-1.8 from cvs and 1.9 from cvs. There appears to  
|be an issue when super is called in the subclass and the parent class  
|has method\_missing defined. Strangely, if super is called with  
|explicit arguments, no segfault occurs. Likewise, if the method  
|definition in the subclass is modified slightly (see below) the  
|segfault is avoided.

A bug was in super without any argument. The patch attached should  
fix the bug. Thank you for reporting it.

```
						matz.

```

— eval.c 3 Mar 2006 17:39:26 -0000 1.616.2.165  
+++ eval.c 23 Mar 2006 01:48:22 -0000  
@@ -5578,7 +5578,18 @@ method\_missing(obj, id, argc, argv, call  
}

- if (argc \< 0) {
- VALUE tmp;

- nargv = ALLOCA\_N(VALUE, argc+1);
- nargv[0] = ID2SYM(id);
- MEMCPY(nargv+1, argv, VALUE, argc);

- argc = -argc-1;

- tmp = splat\_value(argv[argc]);

- nargv = ALLOCA\_N(VALUE, argc + RARRAY(tmp)-\>len + 1);

- MEMCPY(nargv+1, argv, VALUE, argc);

- MEMCPY(nargv+1+argc, RARRAY(tmp)-\>ptr, VALUE, RARRAY(tmp)-\>len);

- argc += RARRAY(tmp)-\>len;

- }

- else {

- nargv = ALLOCA\_N(VALUE, argc+1);

- MEMCPY(nargv+1, argv, VALUE, argc);

- }

- nargv[0] = ID2SYM(id);  
return rb\_funcall2(obj, missing, argc+1, nargv);

---

<div class="post-metadata">

**Author:** ![bhutchins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f1d935/32.png) [@bhutchins](https://www.ruby-forum.com/u/bhutchins)\
**Post date:** [March 23, 2006, 2:55am UTC](https://www.ruby-forum.com/t/bug-segfault-when-using-super-and-method-missing/55699/4 "2006-03-23T02:55:12Z")

</div>

Hi,

In message “Re: bug: segfault when using super and method\_missing”  
on Thu, 23 Mar 2006 10:50:01 +0900, Joel VanderWerf  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|It’s ok on  
|  
|ruby 1.8.4 (2005-12-24) [i686-linux]  
|  
|built from source with the default options (on ubuntu).

It happens only on CVS top.

```
						matz.

```

---

<div class="post-metadata">

**Author:** ![bhutchins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f1d935/32.png) [@bhutchins](https://www.ruby-forum.com/u/bhutchins)\
**Post date:** [March 23, 2006, 3:01am UTC](https://www.ruby-forum.com/t/bug-segfault-when-using-super-and-method-missing/55699/5 "2006-03-23T03:01:10Z")

</div>

On Mar 22, 2006, at 5:49 PM, Yukihiro M. wrote:

> A bug was in super without any argument. The patch attached should  
> fix the bug. Thank you for reporting it.

Thanks for your help and the quick patch!

-Brad

---

<div class="post-metadata">

**Author:** ![bhutchins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f1d935/32.png) [@bhutchins](https://www.ruby-forum.com/u/bhutchins)\
**Post date:** [March 23, 2006, 2:50am UTC](https://www.ruby-forum.com/t/bug-segfault-when-using-super-and-method-missing/55699/6 "2006-03-23T02:50:26Z")

</div>

Brad H. wrote:

> Hello,
> 
> The following code produces a segfault with ruby-1.8.4 from gentoo, as

It’s ok on

ruby 1.8.4 (2005-12-24) [i686-linux]

built from source with the default options (on ubuntu).
