From 35c88d99e3da75086ff88fe2628e613903493fff Mon Sep 17 00:00:00 2001 From: MechSlayer <0jcrespo1996@gmail.com> Date: Thu, 11 Sep 2025 06:19:50 +0200 Subject: [PATCH] fix: make win32's drang_fs_get_cwd only fail with ENOMEM when the buffer is not null, and correctly exclude the null terminator when the buffer size is too small --- Source/DrangPlatform/Source/win32/fs/dir.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/DrangPlatform/Source/win32/fs/dir.c b/Source/DrangPlatform/Source/win32/fs/dir.c index 1e10dcf..2a3fcfb 100644 --- a/Source/DrangPlatform/Source/win32/fs/dir.c +++ b/Source/DrangPlatform/Source/win32/fs/dir.c @@ -132,10 +132,10 @@ int drang_fs_get_cwd(char *buffer, size_t size, size_t *out_size) } if (out_size) { - *out_size = length; + *out_size = length > size ? length - 1 : length; // Exclude null terminator if the buffer is too small } - DRANG_CHECK(length < size, DRANG_ENOMEM); + DRANG_CHECK(buffer != NULL && length < size, DRANG_ENOMEM); DRANG_END_TRY_IGNORE() }