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?= 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. --- dir.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'dir.c') diff --git a/dir.c b/dir.c index 42e5304c0f..9c9d40df85 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) 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) 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) } 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 v1.2.1