ruby-changes:62007
From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Mon, 29 Jun 2020 11:07:17 +0900 (JST)
Subject: [ruby-changes:62007] 99073f49bf (master): glob_opendir: do not goto into a branch
https://git.ruby-lang.org/ruby.git/commit/?id=99073f49bf From 99073f49bf97e1d2f2caab97045de5011edf04b8 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: Fri, 12 Jun 2020 14:08:48 +0900 Subject: glob_opendir: 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/dir.c b/dir.c index 42e5304..9c9d40d 100644 --- a/dir.c +++ b/dir.c @@ -2182,6 +2182,7 @@ glob_opendir(ruby_glob_entries_t *ent, DIR *dirp, int flags, rb_encoding *enc) https://github.com/ruby/ruby/blob/trunk/dir.c#L2182 MEMZERO(ent, ruby_glob_entries_t, 1); if (flags & FNM_GLOB_NOSORT) { ent->nosort.dirp = dirp; + return ent; } else { void *newp; @@ -2202,10 +2203,7 @@ glob_opendir(ruby_glob_entries_t *ent, DIR *dirp, int flags, rb_encoding *enc) https://github.com/ruby/ruby/blob/trunk/dir.c#L2203 while ((dp = READDIR(dirp, enc)) != NULL) { rb_dirent_t *rdp = dirent_copy(dp, NULL); if (!rdp) { - nomem: - glob_dir_finish(ent, 0); - closedir(dirp); - return NULL; + goto nomem; } if (count >= capacity) { capacity += 256; @@ -2226,8 +2224,13 @@ glob_opendir(ruby_glob_entries_t *ent, DIR *dirp, int flags, rb_encoding *enc) https://github.com/ruby/ruby/blob/trunk/dir.c#L2224 } ruby_qsort(ent->sort.entries, ent->sort.count, sizeof(ent->sort.entries[0]), glob_sort_cmp, NULL); + return ent; + + nomem: + glob_dir_finish(ent, 0); + closedir(dirp); + return NULL; } - return ent; } static rb_dirent_t * -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/