diff --git a/glib/dirent/dirent.c b/glib/dirent/dirent.c index 26b6cb1e5..5b8f3ff80 100644 --- a/glib/dirent/dirent.c +++ b/glib/dirent/dirent.c @@ -135,7 +135,7 @@ _topendir (const _TCHAR *szPath) nd->dd_dir.d_ino = 0; nd->dd_dir.d_reclen = 0; nd->dd_dir.d_namlen = 0; - memset (nd->dd_dir.d_name, 0, FILENAME_MAX); + memset (nd->dd_dir.d_name, 0, sizeof (nd->dd_dir.d_name)); return nd; } 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. */ }; /* 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 };