From 6fb636050fd0fac9615e6014316b8d42d8370f42 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Fri, 10 Jan 2020 15:00:14 +1100 Subject: [PATCH 1/2] std: fix off by one error in windows process creation --- lib/std/child_process.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/child_process.zig b/lib/std/child_process.zig index 02d8693e2c..156f9f2924 100644 --- a/lib/std/child_process.zig +++ b/lib/std/child_process.zig @@ -636,7 +636,7 @@ pub const ChildProcess = struct { retry: while (it.next()) |search_path| { var ext_it = mem.tokenize(PATHEXT, ";"); while (ext_it.next()) |app_ext| { - const app_basename = try mem.concat(self.allocator, u8, &[_][]const u8{ app_name[0 .. app_name.len - 1], app_ext }); + const app_basename = try mem.concat(self.allocator, u8, &[_][]const u8{ app_name, app_ext }); defer self.allocator.free(app_basename); const joined_path = try fs.path.join(self.allocator, &[_][]const u8{ search_path, app_basename }); From 03e1241b8828ff9e106d46862ca36fcd75cdc3c4 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Fri, 10 Jan 2020 15:03:51 +1100 Subject: [PATCH 2/2] std: avoid an allocation in inner loop --- lib/std/child_process.zig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/std/child_process.zig b/lib/std/child_process.zig index 156f9f2924..6106a88942 100644 --- a/lib/std/child_process.zig +++ b/lib/std/child_process.zig @@ -634,12 +634,12 @@ pub const ChildProcess = struct { var it = mem.tokenize(PATH, ";"); retry: while (it.next()) |search_path| { + const path_no_ext = try fs.path.join(self.allocator, &[_][]const u8{ search_path, app_name }); + defer self.allocator.free(path_no_ext); + var ext_it = mem.tokenize(PATHEXT, ";"); while (ext_it.next()) |app_ext| { - const app_basename = try mem.concat(self.allocator, u8, &[_][]const u8{ app_name, app_ext }); - defer self.allocator.free(app_basename); - - const joined_path = try fs.path.join(self.allocator, &[_][]const u8{ search_path, app_basename }); + const joined_path = try mem.concat(self.allocator, u8, &[_][]const u8{ path_no_ext, app_ext }); defer self.allocator.free(joined_path); const joined_path_w = try unicode.utf8ToUtf16LeWithNull(self.allocator, joined_path);