ruby-changes:62047
From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Mon, 29 Jun 2020 11:08:23 +0900 (JST)
Subject: [ruby-changes:62047] 0358846f8c (master): rb_str_update: do not goto into a branch
https://git.ruby-lang.org/ruby.git/commit/?id=0358846f8c From 0358846f8cb32b3b4e724685b1d72b16fbc8596c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= <shyouhei@r...> Date: Thu, 18 Jun 2020 10:29:25 +0900 Subject: rb_str_update: do not goto into a branch I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. diff --git a/string.c b/string.c index 8ccfac5..1dfbd65 100644 --- a/string.c +++ b/string.c @@ -4729,14 +4729,10 @@ rb_str_update(VALUE str, long beg, long len, VALUE val) https://github.com/ruby/ruby/blob/trunk/string.c#L4729 enc = rb_enc_check(str, val); slen = str_strlen(str, enc); /* rb_enc_check */ - if (slen < beg) { - out_of_range: + if ((slen < beg) || ((beg < 0) && (beg + slen < 0))) { rb_raise(rb_eIndexError, "index %ld out of string", beg); } if (beg < 0) { - if (beg + slen < 0) { - goto out_of_range; - } beg += slen; } assert(beg >= 0); -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/