次のように ungetc を使うと core を吐く場合があります。

akr@helium:~/ruby/ruby$ ./ruby -e 'open("zz", "w+") {|f| f.print "a"; f.ungetc ?x}'
-e:1: [BUG] Segmentation fault
ruby 1.8.1 (2003-12-22) [i686-linux]

Aborted (core dumped)
akr@helium:~/ruby/ruby$ gdb ruby core
GNU gdb 2002-04-01-cvs
Copyright 2002 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"...
Core was generated by `./ruby -e open("zz", "w+") {|f| f.print "a"; f.ungetc ?x}'.
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  0x40095781 in kill () from /lib/libc.so.6
(gdb) where
#0  0x40095781 in kill () from /lib/libc.so.6
#1  0x40095464 in raise () from /lib/libc.so.6
#2  0x40096be1 in abort () from /lib/libc.so.6
#3  0x080c26ea in rb_bug () at error.c:199
#4  0x080a6daf in sigsegv () at signal.c:419
#5  0x400956b8 in sigaction () from /lib/libc.so.6
#6  0x400d6f10 in _IO_free_backup_area () from /lib/libc.so.6
#7  0x400d7ee6 in _IO_unsave_markers () from /lib/libc.so.6
#8  0x400d57ae in _IO_file_close_it () from /lib/libc.so.6
#9  0x400cd12d in fclose () from /lib/libc.so.6
#10 0x0807132a in fptr_finalize (fptr=0x81207e0, noraise=0) at io.c:1360
#11 0x080713da in rb_io_fptr_cleanup (fptr=0x81207e0, noraise=0) at io.c:1381
#12 0x08071477 in rb_io_close (io=1075483040) at io.c:1417
#13 0x08071509 in rb_io_close_m (io=1075483040) at io.c:1437
#14 0x0805b991 in rb_call0 (klass=1075510180, recv=1075483040, id=7609, oid=7609, argc=0, argv=0x0, body=0x401af3d4, 
    nosuper=0) at eval.c:4944
#15 0x0805c3b6 in rb_call (klass=1075510180, recv=1075483040, mid=7609, argc=0, argv=0x0, scope=1) at eval.c:5287
#16 0x0805c5e9 in rb_funcall (recv=1075483040, mid=7609, n=0) at eval.c:5352
#17 0x08071539 in io_close (io=1075483040) at io.c:1445
#18 0x0805ab29 in rb_ensure (b_proc=0x8059f3c <rb_yield>, data1=1075483040, e_proc=0x8071514 <io_close>, data2=1075483040)
    at eval.c:4721
#19 0x080724e3 in rb_io_s_open (argc=2, argv=0xbffff114, klass=1075506340) at io.c:2282
#20 0x080725f8 in rb_f_open (argc=2, argv=0xbffff114) at io.c:2324
#21 0x0805b95e in rb_call0 (klass=1075551400, recv=1075546640, id=7273, oid=7273, argc=2, argv=0xbffff114, 
    body=0x401aff8c, nosuper=0) at eval.c:4938
#22 0x0805c3b6 in rb_call (klass=1075551400, recv=1075546640, mid=7273, argc=2, argv=0xbffff114, scope=1) at eval.c:5287
#23 0x080572ac in rb_eval (self=1075546640, n=0x401a9344) at eval.c:3091
#24 0x0805630c in rb_eval (self=1075546640, n=0x401a91dc) at eval.c:2796
#25 0x08053350 in eval_node (self=1075546640, node=0x401a91dc) at eval.c:1267
#26 0x0805381e in ruby_exec () at eval.c:1436
#27 0x0805387a in ruby_run () at eval.c:1457
#28 0x08051d42 in Letext () at main.c:50
#29 0x4008514f in __libc_start_main () from /lib/libc.so.6
(gdb) 
-- 
[田中 哲][たなか あきら][Tanaka Akira]