зеркало из https://github.com/github/ruby.git
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.
This commit is contained in:
Родитель
7cf4625690
Коммит
224e9c3835
27
signal.c
27
signal.c
|
@ -243,6 +243,20 @@ signm2signo(VALUE *sig_ptr, int negative, int exit, int *prefix_ptr)
|
|||
prefix += signame_prefix_len;
|
||||
}
|
||||
if (len <= (long)prefix) {
|
||||
goto unsupported;
|
||||
}
|
||||
|
||||
if (prefix_ptr) *prefix_ptr = prefix;
|
||||
nmlen = len - prefix;
|
||||
nm += prefix;
|
||||
if (nmlen > LONGEST_SIGNAME) goto unsupported;
|
||||
FOREACH_SIGNAL(sigs, !exit) {
|
||||
if (memcmp(sigs->signm, nm, nmlen) == 0 &&
|
||||
sigs->signm[nmlen] == '\0') {
|
||||
return negative ? -sigs->signo : sigs->signo;
|
||||
}
|
||||
}
|
||||
|
||||
unsupported:
|
||||
if (prefix == signame_prefix_len) {
|
||||
prefix = 0;
|
||||
|
@ -260,19 +274,6 @@ signm2signo(VALUE *sig_ptr, int negative, int exit, int *prefix_ptr)
|
|||
}
|
||||
rb_raise(rb_eArgError, "unsupported signal `%.*s%"PRIsVALUE"'",
|
||||
prefix, signame_prefix, vsig);
|
||||
}
|
||||
|
||||
if (prefix_ptr) *prefix_ptr = prefix;
|
||||
nmlen = len - prefix;
|
||||
nm += prefix;
|
||||
if (nmlen > LONGEST_SIGNAME) goto unsupported;
|
||||
FOREACH_SIGNAL(sigs, !exit) {
|
||||
if (memcmp(sigs->signm, nm, nmlen) == 0 &&
|
||||
sigs->signm[nmlen] == '\0') {
|
||||
return negative ? -sigs->signo : sigs->signo;
|
||||
}
|
||||
}
|
||||
goto unsupported;
|
||||
}
|
||||
|
||||
static const char*
|
||||
|
|
Загрузка…
Ссылка в новой задаче