The branch main has been updated by des:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=42e613018da50ee6877d24815c7626d79629e707

commit 42e613018da50ee6877d24815c7626d79629e707
Author:     Dag-Erling Smørgrav <d...@freebsd.org>
AuthorDate: 2025-07-09 20:34:22 +0000
Commit:     Dag-Erling Smørgrav <d...@freebsd.org>
CommitDate: 2025-07-09 20:34:22 +0000

    opendir, readdir, telldir: Use the correct types.
    
    Use either size_t or off_t (as appropriate) instead of long.
    
    Sponsored by:   Klara, Inc.
    Reviewed by:    kevans
    Differential Revision:  https://reviews.freebsd.org/D51210
---
 lib/libc/gen/gen-private.h | 4 ++--
 lib/libc/gen/opendir2.c    | 6 ++++--
 lib/libc/gen/readdir.c     | 4 ++--
 lib/libc/gen/telldir.c     | 4 ++--
 lib/libc/gen/telldir.h     | 6 +++---
 5 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/lib/libc/gen/gen-private.h b/lib/libc/gen/gen-private.h
index 3792a61ff942..b6749b3435cd 100644
--- a/lib/libc/gen/gen-private.h
+++ b/lib/libc/gen/gen-private.h
@@ -43,8 +43,8 @@ struct pthread_mutex;
  */
 struct _dirdesc {
        int     dd_fd;          /* file descriptor associated with directory */
-       long    dd_loc;         /* offset in current buffer */
-       long    dd_size;        /* amount of data returned by getdirentries */
+       size_t  dd_loc;         /* offset in current buffer */
+       size_t  dd_size;        /* amount of data returned by getdirentries */
        char    *dd_buf;        /* data buffer */
        int     dd_len;         /* size of data buffer */
        off_t   dd_seek;        /* magic cookie returned by getdirentries */
diff --git a/lib/libc/gen/opendir2.c b/lib/libc/gen/opendir2.c
index 7f207ed73441..c5c2e662efd8 100644
--- a/lib/libc/gen/opendir2.c
+++ b/lib/libc/gen/opendir2.c
@@ -264,6 +264,7 @@ DIR *
 __opendir_common(int fd, int flags, bool use_current_pos)
 {
        DIR *dirp;
+       ssize_t ret;
        int incr;
        int saved_errno;
        bool unionstack;
@@ -313,10 +314,11 @@ __opendir_common(int fd, int flags, bool use_current_pos)
                         * to prime dd_seek.  This also checks if the
                         * fd passed to fdopendir() is a directory.
                         */
-                       dirp->dd_size = _getdirentries(dirp->dd_fd,
+                       ret = _getdirentries(dirp->dd_fd,
                            dirp->dd_buf, dirp->dd_len, &dirp->dd_seek);
-                       if (dirp->dd_size < 0)
+                       if (ret < 0)
                                goto fail;
+                       dirp->dd_size = (size_t)ret;
                        dirp->dd_flags |= __DTF_SKIPREAD;
                } else {
                        dirp->dd_size = 0;
diff --git a/lib/libc/gen/readdir.c b/lib/libc/gen/readdir.c
index 2a2fa999b7ce..32603c0b4677 100644
--- a/lib/libc/gen/readdir.c
+++ b/lib/libc/gen/readdir.c
@@ -48,8 +48,8 @@ struct dirent *
 _readdir_unlocked(DIR *dirp, int flags)
 {
        struct dirent *dp;
-       long initial_seek;
-       long initial_loc = 0;
+       off_t initial_seek;
+       size_t initial_loc = 0;
 
        for (;;) {
                if (dirp->dd_loc >= dirp->dd_size) {
diff --git a/lib/libc/gen/telldir.c b/lib/libc/gen/telldir.c
index b751fafd975f..1731cc4d7a2c 100644
--- a/lib/libc/gen/telldir.c
+++ b/lib/libc/gen/telldir.c
@@ -118,7 +118,7 @@ _seekdir(DIR *dirp, long loc)
        struct dirent *dp;
        union ddloc_packed ddloc;
        off_t loc_seek;
-       long loc_loc;
+       size_t loc_loc;
 
        ddloc.l = loc;
 
@@ -171,7 +171,7 @@ _seekdir(DIR *dirp, long loc)
  * fetching a new block to fix any such telldir locations.
  */
 void
-_fixtelldir(DIR *dirp, long oldseek, long oldloc)
+_fixtelldir(DIR *dirp, off_t oldseek, size_t oldloc)
 {
        struct ddloc_mem *lp;
 
diff --git a/lib/libc/gen/telldir.h b/lib/libc/gen/telldir.h
index 6d113491e819..02fd52af9060 100644
--- a/lib/libc/gen/telldir.h
+++ b/lib/libc/gen/telldir.h
@@ -46,9 +46,9 @@
  */
 struct ddloc_mem {
        LIST_ENTRY(ddloc_mem) loc_lqe; /* entry in list */
-       long    loc_index;      /* key associated with structure */
+       size_t  loc_index;      /* key associated with structure */
        off_t   loc_seek;       /* magic cookie returned by getdirentries */
-       long    loc_loc;        /* offset of entry in buffer */
+       size_t  loc_loc;        /* offset of entry in buffer */
 };
 
 #ifdef __LP64__
@@ -102,7 +102,7 @@ bool                _filldir(DIR *, bool);
 struct dirent  *_readdir_unlocked(DIR *, int);
 void           _reclaim_telldir(DIR *);
 void           _seekdir(DIR *, long);
-void           _fixtelldir(DIR *dirp, long oldseek, long oldloc);
+void           _fixtelldir(DIR *dirp, off_t oldseek, size_t oldloc);
 DIR            *__opendir_common(int, int, bool);
 
 #define        RDU_SKIP        0x0001

Reply via email to