remove ugly sizeof(DEV_FD) - 1

This commit is contained in:
Jōshin 2023-12-18 16:19:07 -05:00
parent a66ccdcf5d
commit 45ee600239
No known key found for this signature in database

View file

@ -39,6 +39,7 @@
#define KERN_PROC_PATHNAME_FREEBSD 12 #define KERN_PROC_PATHNAME_FREEBSD 12
#define KERN_PROC_PATHNAME_NETBSD 5 #define KERN_PROC_PATHNAME_NETBSD 5
#define DEV_FD "/dev/fd/" #define DEV_FD "/dev/fd/"
#define STRLEN_DEV_FD (sizeof(DEV_FD) - 1)
static struct { static struct {
atomic_uint once; atomic_uint once;
@ -144,10 +145,10 @@ static inline void InitProgramExecutableNameImpl(void) {
empty string to obviate the TOCTOU problem between loader and binary. empty string to obviate the TOCTOU problem between loader and binary.
*/ */
if ((!IsNetbsd() && !IsOpenbsd() && !IsXnu()) /* any others? */ || if ((!IsNetbsd() && !IsOpenbsd() && !IsXnu()) /* any others? */ ||
0 != strncmp(DEV_FD, __program_executable_name, sizeof(DEV_FD) - 1) || 0 != strncmp(DEV_FD, __program_executable_name, STRLEN_DEV_FD) ||
!__program_executable_name[sizeof(DEV_FD) - 1] || !__program_executable_name[STRLEN_DEV_FD] ||
__program_executable_name[sizeof(DEV_FD) - 1] == '.' || __program_executable_name[STRLEN_DEV_FD] == '.' ||
strchr(__program_executable_name + sizeof(DEV_FD) - 1, '/')) { strchr(__program_executable_name + STRLEN_DEV_FD, '/')) {
goto UseEmpty; goto UseEmpty;
} }
} }