[glib: 2/4] dirent: Add trailing nul delimiter to FILENAME_MAX




commit 496135c569788334b4256c72e781cad7dbc9404a
Author: Philip Withnall <pwithnall endlessos org>
Date:   Mon Apr 19 19:23:10 2021 +0100

    dirent: Add trailing nul delimiter to FILENAME_MAX
    
    `FILENAME_MAX` is not guaranteed to include a trailing nul delimiter, so
    explicitly add one.
    
    See
    https://www.gnu.org/software/libc/manual/html_node/Limits-for-Files.html:
    `PATH_MAX` is explicitly defined to include a nul delimiter;
    `FILENAME_MAX` is not.
    
    See also https://twitter.com/pid_eins/status/1357008940886818822.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 glib/dirent/dirent.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/glib/dirent/dirent.h b/glib/dirent/dirent.h
index 237665b4e..857710f6a 100644
--- a/glib/dirent/dirent.h
+++ b/glib/dirent/dirent.h
@@ -22,7 +22,7 @@ struct dirent
        long            d_ino;          /* Always zero. */
        unsigned short  d_reclen;       /* Always zero. */
        unsigned short  d_namlen;       /* Length of name in d_name. */
-       char            d_name[FILENAME_MAX]; /* File name. */
+       char            d_name[FILENAME_MAX+1]; /* File name plus nul delimiter. */
 };
 
 #ifdef _WIN64
@@ -76,7 +76,7 @@ struct _wdirent
        long            d_ino;          /* Always zero. */
        unsigned short  d_reclen;       /* Always zero. */
        unsigned short  d_namlen;       /* Length of name in d_name. */
-       wchar_t         d_name[FILENAME_MAX]; /* File name. */
+       wchar_t         d_name[FILENAME_MAX+1]; /* File name plus nul delimiter. */
 };
 
 /*


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]