ruby-changes:46758
From: nobu <ko1@a...>
Date: Wed, 24 May 2017 23:26:14 +0900 (JST)
Subject: [ruby-changes:46758] nobu:r58873 (trunk): dir.c: prefer NAMLEN to d_name
nobu 2017-05-24 23:26:09 +0900 (Wed, 24 May 2017) New Revision: 58873 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58873 Log: dir.c: prefer NAMLEN to d_name * dir.c (glob_helper): prefer NAMLEN, do not assume d_name is NUL terminated everywhere. Modified files: trunk/dir.c Index: dir.c =================================================================== --- dir.c (revision 58872) +++ dir.c (revision 58873) @@ -1972,21 +1972,21 @@ glob_helper( https://github.com/ruby/ruby/blob/trunk/dir.c#L1972 int dotfile = 0; IF_NORMALIZE_UTF8PATH(VALUE utf8str = Qnil); - if (recursive && dp->d_name[0] == '.') { + name = dp->d_name; + namlen = NAMLEN(dp); + if (recursive && name[0] == '.') { ++dotfile; - if (!dp->d_name[1]) { + if (namlen == 1) { /* unless DOTMATCH, skip current directories not to recurse infinitely */ if (!(flags & FNM_DOTMATCH)) continue; ++dotfile; } - else if (dp->d_name[1] == '.' && !dp->d_name[2]) { + else if (namlen == 2 && name[1] == '.') { /* always skip parent directories not to recurse infinitely */ continue; } } - name = dp->d_name; - namlen = NAMLEN(dp); # if NORMALIZE_UTF8PATH if (norm_p && has_nonascii(name, namlen)) { if (!NIL_P(utf8str = rb_str_normalize_ospath(name, namlen))) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/