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>
This commit is contained in:
Philip Withnall 2021-04-19 19:23:10 +01:00
parent 3c027268a4
commit 496135c569

View File

@ -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. */
};
/*