https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112014-10-31T15:12:48ZRuby Issue Tracking SystemRuby master - Bug #10453: NUM2CHR() does not perform additional bounds checkshttps://redmine.ruby-lang.org/issues/10453?journal_id=497552014-10-31T15:12:48Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/49755/diff?detail_id=35912">diff</a>)</li><li><strong>Category</strong> set to <i>core</i></li><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li><li><strong>Assignee</strong> set to <i>matz (Yukihiro Matsumoto)</i></li><li><strong>Target version</strong> set to <i>2.2.0</i></li></ul><p><code>NUM2CHR</code> rather should never raise <code>RangeError</code> for any arguments?</p> Ruby master - Bug #10453: NUM2CHR() does not perform additional bounds checkshttps://redmine.ruby-lang.org/issues/10453?journal_id=497562014-10-31T20:33:29Zsilverhammermba (Max Anselm)silverhammermba+ruby@gmail.com
<ul></ul><p>I would expect it to raise <code>RangeError</code> if the num exceeds the size of a <code>char</code>. That is the behavior of the all of the other <code>NUM2*</code> macros.</p> Ruby master - Bug #10453: NUM2CHR() does not perform additional bounds checkshttps://redmine.ruby-lang.org/issues/10453?journal_id=693442018-01-05T21:01:17Znaruse (Yui NARUSE)naruse@airemix.jp
<ul><li><strong>Target version</strong> deleted (<del><i>2.2.0</i></del>)</li></ul> Ruby master - Bug #10453: NUM2CHR() does not perform additional bounds checkshttps://redmine.ruby-lang.org/issues/10453?journal_id=806442019-08-12T02:41:32Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>File</strong> <a href="/attachments/7989">num2chr-range-check-10453.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/7989/num2chr-range-check-10453.patch">num2chr-range-check-10453.patch</a> added</li></ul><p>Attached is a patch that will add a range check to <code>NUM2CHR</code>. However, it breaks a test:</p>
<pre><code>1) Error:
TestStringIO#test_putc_nonascii:
RangeError: value to large to convert to char: 12356
/home/jeremy/tmp/ruby/test/stringio/test_stringio.rb:567:in `putc'
/home/jeremy/tmp/ruby/test/stringio/test_stringio.rb:567:in `test_putc_nonascii'
</code></pre>
<p>It is possibly, maybe even likely, that it will break third party C extensions as well (403 matches for <code>NUM2CHR</code> for Ruby on GitHub: <a href="https://github.com/search?l=Ruby&q=NUM2CHR&type=Code" class="external">https://github.com/search?l=Ruby&q=NUM2CHR&type=Code</a>).</p> Ruby master - Bug #10453: NUM2CHR() does not perform additional bounds checkshttps://redmine.ruby-lang.org/issues/10453?journal_id=806492019-08-12T04:48:58Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>As <code>CHR</code> should stand for <code>char</code> type of C, so exceeding the limit of <code>char</code> will make confusion, I guess.</p>
<p>I'm curious for what purpose <a class="user active user-mention" href="https://redmine.ruby-lang.org/users/3466">@silverhammermba (Max Anselm)</a> needs the range check.<br>
If it is to get a codepoint, I don't think extracting the first byte from a string argument reasonable.</p> Ruby master - Bug #10453: NUM2CHR() does not perform additional bounds checkshttps://redmine.ruby-lang.org/issues/10453?journal_id=829362019-12-03T15:38:16Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Related to</strong> <i><a class="issue tracker-1 status-5 priority-4 priority-default closed" href="/issues/15460">Bug #15460</a>: Behaviour of String#setbyte changed</i> added</li></ul> Ruby master - Bug #10453: NUM2CHR() does not perform additional bounds checkshttps://redmine.ruby-lang.org/issues/10453?journal_id=829392019-12-03T15:44:47Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Rejected</i></li></ul><p>See <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Behaviour of String#setbyte changed (Closed)" href="https://redmine.ruby-lang.org/issues/15460">#15460</a>. <code>String#setbyte</code> has accepted not only 0..255 but also any integers. Once it had been limited only to 0..255, but it caused a compatibility issue, and eventually was reverted.</p>
<p>I don't think that this is a good idea in terms of compatibility, unless there is a special reason to make it strict.</p>
<p>I tentatively close this because there is no response from OP. If we have a response, I'd be happy to reopen.</p>