[glib: 3/4] gdir: Add trailing nul delimiter to FILENAME_MAX




commit 3131a6149e71208e5e5f077ed42fd6254b115a93
Author: Philip Withnall <pwithnall endlessos org>
Date:   Mon Apr 19 19:24:08 2021 +0100

    gdir: 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/gdir.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
---
diff --git a/glib/gdir.c b/glib/gdir.c
index c26edc1dc..b07eb5c20 100644
--- a/glib/gdir.c
+++ b/glib/gdir.c
@@ -60,7 +60,9 @@ struct _GDir
   DIR *dirp;
 #endif
 #ifdef G_OS_WIN32
-  gchar utf8_buf[FILENAME_MAX*4];
+  /* maximum encoding of FILENAME_MAX UTF-8 characters, plus a nul terminator
+   * (FILENAME_MAX is not guaranteed to include one) */
+  gchar utf8_buf[FILENAME_MAX*4 + 1];
 #endif
 };
 


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