From 55d954721e25ada90482f6d3f751a12fc982620b Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Fri, 20 Oct 2023 23:30:40 -0500 Subject: Raise TypeError for bad IO::Buffer.map argument (#8728) * Raise TypeError when IO::Buffer.map argument is neither IO nor implements #fileno * Use UNREACHABLE_CODE Co-authored-by: Nobuyoshi Nakada * Use macro for undef check Co-authored-by: Nobuyoshi Nakada --------- Co-authored-by: Nobuyoshi Nakada --- io.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'io.c') diff --git a/io.c b/io.c index f4698a2cd5..28b5abb1c5 100644 --- a/io.c +++ b/io.c @@ -2870,8 +2870,15 @@ rb_io_descriptor(VALUE io) return fptr->fd; } else { - return RB_NUM2INT(rb_funcall(io, id_fileno, 0)); + VALUE fileno = rb_check_funcall(io, id_fileno, 0, NULL); + if (!UNDEF_P(fileno)) { + return RB_NUM2INT(fileno); + } } + + rb_raise(rb_eTypeError, "expected IO or #fileno, %"PRIsVALUE" given", rb_obj_class(io)); + + UNREACHABLE_RETURN(-1); } int -- cgit v1.2.3