Project

General

Profile

Bug #12793

Warning.warn with non-string object

Added by znz (Kazuhiro NISHIYAMA) almost 4 years ago. Updated almost 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.0dev (2016-09-27 trunk 56273) [x86_64-linux]
[ruby-core:77430]

Description

Warning.warn with non-string argument causes SEGV.
For example, Warning.warn nil.

#1

Updated by nobu (Nobuyoshi Nakada) almost 4 years ago

  • Status changed from Open to Closed

Applied in changeset r56274.


error.c: check argument of Warning.warn

  • error.c (rb_warning_s_warn): the argument must be an ASCII-compatible string. [ruby-core:77430] [Bug #12793]

Updated by znz (Kazuhiro NISHIYAMA) almost 4 years ago

Kernel#warn accepts nil and 1, but Warning.warn raises TypeError.
Is this difference expected?

% ruby -ve 'warn nil; Warning.warn nil'
ruby 2.4.0dev (2016-09-28 trunk 56281) [x86_64-linux]

-e:1:in `warn': wrong argument type nil (expected String) (TypeError)
        from -e:1:in `<main>'
% ruby -ve 'warn 1; Warning.warn 1'
ruby 2.4.0dev (2016-09-28 trunk 56281) [x86_64-linux]
1
-e:1:in `warn': wrong argument type Integer (expected String) (TypeError)
        from -e:1:in `<main>'

Updated by nobu (Nobuyoshi Nakada) almost 4 years ago

While Kernel#warn should be generous since it is a public API,
Warning.warn is a method called by the internal and should be strict.

Also available in: Atom PDF