about summary refs log tree commit diff
path: root/io/fts.c
diff options
context:
space:
mode:
Diffstat (limited to 'io/fts.c')
-rw-r--r--io/fts.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/io/fts.c b/io/fts.c
index 5bc1aff015..fe5750ab56 100644
--- a/io/fts.c
+++ b/io/fts.c
@@ -661,13 +661,16 @@ fts_build(sp, type)
 	/* Read the directory, attaching each entry to the `link' pointer. */
 	adjaddr = NULL;
 	for (head = tail = NULL, nitems = 0; dp = readdir(dirp);) {
+		int namlen;
+
 		if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
 			continue;
 
-		if ((p = fts_alloc(sp, dp->d_name, (int)dp->d_namlen)) == NULL)
+		namlen = _D_EXACT_NAMLEN (dp);
+		if ((p = fts_alloc(sp, dp->d_name, namlen)) == NULL)
 			goto mem1;
-		if (dp->d_namlen > maxlen) {
-			if (fts_palloc(sp, (size_t)dp->d_namlen)) {
+		if (namlen > maxlen) {
+			if (fts_palloc(sp, (size_t)namlen)) {
 				/*
 				 * No more memory for path or structures.  Save
 				 * errno, free up the current structure and the
@@ -687,7 +690,7 @@ mem1:				saved_errno = errno;
 			maxlen = sp->fts_pathlen - sp->fts_cur->fts_pathlen - 1;
 		}
 
-		p->fts_pathlen = len + dp->d_namlen + 1;
+		p->fts_pathlen = len + namlen + 1;
 		p->fts_parent = sp->fts_cur;
 		p->fts_level = level;