aboutsummaryrefslogtreecommitdiffstats
path: root/dir.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-24 14:26:09 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-24 14:26:09 +0000
commit6d600b1d7500a070be0885dbb67ac77289e2c6e6 (patch)
tree5658250df0c765cdf3dc7446a80a7e516dc6f9ca /dir.c
parente4f1108afce5b59919ade0f8d9aae18790b3fbcc (diff)
downloadruby-6d600b1d7500a070be0885dbb67ac77289e2c6e6.tar.gz
dir.c: prefer NAMLEN to d_name
* dir.c (glob_helper): prefer NAMLEN, do not assume d_name is NUL terminated everywhere. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/dir.c b/dir.c
index 10ee2a78f8..9a53c7141f 100644
--- a/dir.c
+++ b/dir.c
@@ -1972,21 +1972,21 @@ glob_helper(
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))) {