From f254c27966ef9c6b47b3a1e2845ffa52dbc6aea8 Mon Sep 17 00:00:00 2001 From: Manu Linares Date: Thu, 15 Jan 2026 17:23:30 -0300 Subject: [PATCH] std/io/os/temp_directory.c3: fix INVALID_PATH in Win32 native_temp_directory (#2762) * std/io/os/temp_directory.c3: fix INVALID_PATH in Windows native_temp_directory - Use the actual length from GetTempPathW for Windows temp path slice - We can remove the workaround in the test_suite_runner for WIN32 and create all directories in %temp% now * Updated releasenotes. --------- Co-authored-by: Christoffer Lerno --- lib/std/io/os/temp_directory.c3 | 7 ++++--- releasenotes.md | 1 + test/src/test_suite_runner.c3 | 6 +----- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/std/io/os/temp_directory.c3 b/lib/std/io/os/temp_directory.c3 index 7b03efad7..671ab4e96 100644 --- a/lib/std/io/os/temp_directory.c3 +++ b/lib/std/io/os/temp_directory.c3 @@ -122,9 +122,10 @@ fn Path? native_temp_directory(Allocator allocator) @if(env::WIN32) => @pool() { Win32_DWORD len = win32::getTempPathW(0, null); if (!len) return io::GENERAL_ERROR?; - Char16[] buff = mem::talloc_array(Char16, len + (usz)1); - if (!win32::getTempPathW(len, buff)) return io::GENERAL_ERROR?; - return path::new(allocator, string::tfrom_utf16(buff[:len])); + Char16[] buff = mem::talloc_array(Char16, len); + Win32_DWORD res = win32::getTempPathW(len, buff); + if (!res) return io::GENERAL_ERROR?; + return path::new(allocator, string::tfrom_utf16(buff[:res])); } module std::io::os @if(env::NO_LIBC); diff --git a/releasenotes.md b/releasenotes.md index 2217b7810..d33eef73b 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -60,6 +60,7 @@ - bitorder::read and bitorder::write may fail because of unaligned access #2734. - Fix `LinkedList.to_format` to properly iterate linked list for printing. - Hashing a vector would not use the entire vector in some cases. +- Fix to `temp_directory` on Windows #2762. ### Stdlib changes - Add `ThreadPool` join function to wait for all threads to finish in the pool without destroying the threads. diff --git a/test/src/test_suite_runner.c3 b/test/src/test_suite_runner.c3 index 81d20eb7b..e2cc53e17 100644 --- a/test/src/test_suite_runner.c3 +++ b/test/src/test_suite_runner.c3 @@ -704,11 +704,7 @@ fn int main(String[] args) context.start_cwd = path::tcwd()!!; context.print_mutex.init()!!; - $if env::WIN32: - context.test_root = context.start_cwd; - $else - context.test_root = path::temp_directory(mem)!!; - $endif + context.test_root = path::temp_directory(mem)!!; Path? path = args[1].to_tpath(); if (catch path) arg_error_exit(appname, "Invalid compiler path: %s", args[1]);