[ruby-dev:24291] Enumerable#sort_by with callcc dumps core

From: Tanaka Akira <akr@...17n.org>
Date: 2004-09-19 15:32:51 UTC
List: ruby-dev #24291
次のようにすると core を吐きます。

% ./ruby -e '
arr = (1..100).map {|i| i.to_s }
class << arr[50]; self; end.send(:define_method, :<=>) {|v|
  if not defined? $result
    callcc {|k| $k = k }
  else
     $result.clear; $result.compact!
  end
  1
}
$result = arr.sort_by {|i| i }
$k.call
'
-e:11: [BUG] Segmentation fault
ruby 1.8.2 (2004-09-17) [i686-linux]

zsh: abort (core dumped)  ./ruby -e 
% gdb ruby core                                             
GNU gdb 6.1-debian
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-linux"...Using host libthread_db library "/lib/libthread_db.so.1".

Core was generated by `./ruby -e 
arr = (1..100).map {|i| i.to_s }
class << arr[50]; self; end.send(:d'.
Program terminated with signal 6, Aborted.
Reading symbols from /lib/libdl.so.2...done.
Loaded symbols for /lib/libdl.so.2
Reading symbols from /lib/libcrypt.so.1...done.
Loaded symbols for /lib/libcrypt.so.1
Reading symbols from /lib/libm.so.6...done.
Loaded symbols for /lib/libm.so.6
Reading symbols from /lib/libc.so.6...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
#0  0x4009e721 in kill () from /lib/libc.so.6
(gdb) bt
#0  0x4009e721 in kill () from /lib/libc.so.6
#1  0x4009e4c5 in raise () from /lib/libc.so.6
#2  0x4009f9e8 in abort () from /lib/libc.so.6
#3  0x080caf66 in rb_bug (fmt=0x0) at error.c:214
#4  0x080aafa2 in sigsegv (sig=11) at signal.c:446
#5  <signal handler called>
#6  0x080c9fdc in sort_by_cmp (a=0x81282f4, b=0x8128324) at enum.c:406
#7  0x080b9458 in ruby_qsort (base=0x1, nel=100, size=4, 
    cmp=0x80c9fc0 <sort_by_cmp>) at util.c:581
#8  0x080ca0df in enum_sort_by (obj=135045056) at enum.c:494
#9  0x08067d61 in call_cfunc (func=0x80ca020 <enum_sort_by>, recv=1075608296, 
    len=1, argc=4, argv=0x0) at eval.c:5378
#10 0x0805bef2 in rb_call0 (klass=1075672716, recv=1075608296, id=3689, oid=2, 
    argc=0, argv=0x0, body=0x401d7600, nosuper=0) at eval.c:5509
#11 0x0805c748 in rb_call (klass=1075672716, recv=1075608296, mid=3689, 
    argc=0, argv=0x0, scope=0) at eval.c:5730
#12 0x08057930 in rb_eval (self=1075673536, n=0x2) at ruby.h:631
#13 0x08056d1a in rb_eval (self=1075673536, n=0x2) at eval.c:2949
#14 0x08057288 in rb_eval (self=1075673536, n=0x2) at eval.c:3414
#15 0x08053e3b in ruby_exec () at eval.c:1456
#16 0x08053e80 in ruby_run () at eval.c:1477
#17 0x08052025 in main (argc=2, argv=0x2, envp=0xbffff8a4) at main.c:50
(gdb) 
-- 
[田中 哲][たなか あきら][Tanaka Akira]

In This Thread

Prev Next