aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-24 23:51:48 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-24 23:51:48 -0800
commitd4ce045f9ee98d02db9228920497b30ffc3a2af1 (patch)
tree48ce43d99994f5ee77b4cfa2dbcc102e4d8290a5
parent7f65875406f90491010b71716f1d1eadd24c408e (diff)
downloadbun-d4ce045f9ee98d02db9228920497b30ffc3a2af1.tar.gz
bun-d4ce045f9ee98d02db9228920497b30ffc3a2af1.tar.zst
bun-d4ce045f9ee98d02db9228920497b30ffc3a2af1.zip
More careful about the lifetime of alias
-rw-r--r--src/install/install.zig19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/install/install.zig b/src/install/install.zig
index e7cc1e332..6d9bd5409 100644
--- a/src/install/install.zig
+++ b/src/install/install.zig
@@ -5696,10 +5696,21 @@ pub const PackageManager = struct {
resolution: Resolution,
) void {
const buf = this.lockfile.buffers.string_bytes.items;
- const alias = if (this.lockfile.alias_map.get(package_id)) |str| str.slice(buf) else name;
- std.mem.copy(u8, &this.destination_dir_subpath_buf, alias);
- this.destination_dir_subpath_buf[alias.len] = 0;
- var destination_dir_subpath: [:0]u8 = this.destination_dir_subpath_buf[0..alias.len :0];
+
+ const destination_dir_subpath: [:0]u8 = brk: {
+ var alias = name;
+ if (this.lockfile.alias_map.get(package_id)) |str| {
+ alias = str.slice(buf);
+ std.mem.copy(u8, &this.destination_dir_subpath_buf, alias);
+ this.destination_dir_subpath_buf[alias.len] = 0;
+ break :brk this.destination_dir_subpath_buf[0..alias.len :0];
+ }
+
+ std.mem.copy(u8, &this.destination_dir_subpath_buf, alias);
+ this.destination_dir_subpath_buf[alias.len] = 0;
+ break :brk this.destination_dir_subpath_buf[0..alias.len :0];
+ };
+
var resolution_buf: [512]u8 = undefined;
const extern_string_buf = this.lockfile.buffers.extern_strings.items;
var resolution_label = std.fmt.bufPrint(&resolution_buf, "{}", .{resolution.fmt(buf)}) catch unreachable;