From 224e9c383598a9f09a5fa5736a098be538316311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Tue, 16 Jun 2020 15:46:30 +0900 Subject: [PATCH] signm2signo: 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. --- signal.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/signal.c b/signal.c index 4e76c75853..5361b8c232 100644 --- a/signal.c +++ b/signal.c @@ -243,23 +243,7 @@ signm2signo(VALUE *sig_ptr, int negative, int exit, int *prefix_ptr) prefix += signame_prefix_len; } if (len <= (long)prefix) { - unsupported: - if (prefix == signame_prefix_len) { - prefix = 0; - } - else if (prefix > signame_prefix_len) { - prefix -= signame_prefix_len; - len -= prefix; - vsig = rb_str_subseq(vsig, prefix, len); - prefix = 0; - } - else { - len -= prefix; - vsig = rb_str_subseq(vsig, prefix, len); - prefix = signame_prefix_len; - } - rb_raise(rb_eArgError, "unsupported signal `%.*s%"PRIsVALUE"'", - prefix, signame_prefix, vsig); + goto unsupported; } if (prefix_ptr) *prefix_ptr = prefix; @@ -272,7 +256,24 @@ signm2signo(VALUE *sig_ptr, int negative, int exit, int *prefix_ptr) return negative ? -sigs->signo : sigs->signo; } } - goto unsupported; + + unsupported: + if (prefix == signame_prefix_len) { + prefix = 0; + } + else if (prefix > signame_prefix_len) { + prefix -= signame_prefix_len; + len -= prefix; + vsig = rb_str_subseq(vsig, prefix, len); + prefix = 0; + } + else { + len -= prefix; + vsig = rb_str_subseq(vsig, prefix, len); + prefix = signame_prefix_len; + } + rb_raise(rb_eArgError, "unsupported signal `%.*s%"PRIsVALUE"'", + prefix, signame_prefix, vsig); } static const char*