https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112016-12-15T18:46:35ZRuby Issue Tracking SystemRuby master - Bug #13037: Segmentation fault on "\n".lines(chomp: true)https://bugs.ruby-lang.org/issues/13037?journal_id=620452016-12-15T18:46:35Zasterite (Ary Borenszweig)asterite@gmail.com
<ul></ul><p>I believe a fix for this is:</p>
<pre><code>Index: string.c
===================================================================
--- string.c (revision 57085)
+++ string.c (working copy)
@@ -7409,8 +7409,9 @@
if (rb_enc_is_newline(prev, e, enc)) {
e = prev;
prev = rb_enc_prev_char(p, e, e, enc);
- if (rb_enc_ascget(prev, e, NULL, enc) == '\r')
+ if (prev && rb_enc_ascget(prev, e, NULL, enc) == '\r') {
e = prev;
+ }
}
return e;
}
</code></pre>
<p>I can verify that this works when I run <code>make && make install</code>, and then trying it on irb.</p>
<p>I tried to write a test for this, in test/ruby/test_string.rb, but doing <code>make test</code> doesn't seem to run it... I make changes to test_string.rb but <code>make test</code> doesn't seem to be running test_string.rb for some reason.</p>
<p>What's the correct way to add a test and try it with HEAD? Thank you!</p> Ruby master - Bug #13037: Segmentation fault on "\n".lines(chomp: true)https://bugs.ruby-lang.org/issues/13037?journal_id=620502016-12-16T01:12:14Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset r57088.</p>
<hr>
<p>fix chomping newline only line</p>
<ul>
<li>string.c (chomp_newline): fix chomping newline only line.<br>
rb_enc_prev_char return NULL if no previous character and must<br>
not call rb_enc_ascget on it. a patch by Ary Borenszweig<br>
at <a href="/issues/13037">[ruby-core:78666]</a>. [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Segmentation fault on "\n".lines(chomp: true) (Closed)" href="https://bugs.ruby-lang.org/issues/13037">#13037</a>]</li>
</ul>