From dfcdbff75bb8b3ced8bd146ae8341ada5ff925a0 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Thu, 1 Feb 2024 18:10:39 -0800 Subject: [PATCH 1/2] windows: fix module.paths getter causing a crash --- src/resolver/resolve_path.zig | 7 +++---- src/resolver/resolver.zig | 11 ++++------- src/string_immutable.zig | 4 ++-- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/resolver/resolve_path.zig b/src/resolver/resolve_path.zig index 663acd1b2da183..4a7df06662c825 100644 --- a/src/resolver/resolve_path.zig +++ b/src/resolver/resolve_path.zig @@ -1122,7 +1122,8 @@ pub fn joinStringBuf(buf: []u8, parts: anytype, comptime _platform: Platform) [] var count: usize = 0; for (parts) |part| { - count += if (part.len > 0) part.len + 1 else 0; + if (part.len == 0) continue; + count += part.len + 1; } if (count * 2 > temp_buf.len) { @@ -1133,9 +1134,7 @@ pub fn joinStringBuf(buf: []u8, parts: anytype, comptime _platform: Platform) [] temp_buf[0] = 0; for (parts) |part| { - if (part.len == 0) { - continue; - } + if (part.len == 0) continue; if (written > 0) { temp_buf[written] = platform.separator(); diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig index eaa045de77c573..2e2cbd7c539ccb 100644 --- a/src/resolver/resolver.zig +++ b/src/resolver/resolver.zig @@ -3278,8 +3278,7 @@ pub const Resolver = struct { const str = brk: { if (std.fs.path.isAbsolute(sliced.slice())) break :brk sliced.slice(); - const dir_path_buf = bufs(.node_modules_paths_buf); - break :brk r.fs.joinBuf(&[_]string{ r.fs.top_level_dir, sliced.slice() }, dir_path_buf); + break :brk bun.path.join(&[_]string{ r.fs.top_level_dir, sliced.slice() }, .auto); }; var arena = std.heap.ArenaAllocator.init(bun.default_allocator); defer arena.deinit(); @@ -3297,11 +3296,9 @@ pub const Resolver = struct { break :brk [2]string{ path_without_trailing_slash, "/node_modules" }; }; - list.append( - bun.String.createUTF8( - bun.strings.concat(stack_fallback_allocator.get(), &path_parts) catch unreachable, - ), - ) catch unreachable; + const nodemodules_path = bun.strings.concat(stack_fallback_allocator.get(), &path_parts) catch unreachable; + bun.path.posixToPlatformInPlace(u8, nodemodules_path); + list.append(bun.String.createUTF8(nodemodules_path)) catch unreachable; dir_info = (r.readDirInfo(std.fs.path.dirname(path_without_trailing_slash) orelse break) catch null) orelse break; } } else { diff --git a/src/string_immutable.zig b/src/string_immutable.zig index 47ad78376894cb..bf000a66e234a1 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -5273,7 +5273,7 @@ pub fn concatWithLength( allocator: std.mem.Allocator, args: []const string, length: usize, -) !string { +) ![]u8 { const out = try allocator.alloc(u8, length); var remain = out; for (args) |arg| { @@ -5287,7 +5287,7 @@ pub fn concatWithLength( pub fn concat( allocator: std.mem.Allocator, args: []const string, -) !string { +) ![]u8 { var length: usize = 0; for (args) |arg| { length += arg.len; From d05cd6aa3148c415b1496512968329c36dddbfb7 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Thu, 1 Feb 2024 19:35:51 -0800 Subject: [PATCH 2/2] use the buffer that was there before --- src/resolver/resolver.zig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig index 2e2cbd7c539ccb..448c9956335030 100644 --- a/src/resolver/resolver.zig +++ b/src/resolver/resolver.zig @@ -3278,7 +3278,8 @@ pub const Resolver = struct { const str = brk: { if (std.fs.path.isAbsolute(sliced.slice())) break :brk sliced.slice(); - break :brk bun.path.join(&[_]string{ r.fs.top_level_dir, sliced.slice() }, .auto); + const dir_path_buf = bufs(.node_modules_paths_buf); + break :brk bun.path.joinStringBuf(dir_path_buf, &[_]string{ r.fs.top_level_dir, sliced.slice() }, .auto); }; var arena = std.heap.ArenaAllocator.init(bun.default_allocator); defer arena.deinit();