Skip to content

Commit a7ae625

Browse files
committed
Replace allocPrintZ with allocPrint and an explcit null terminator
1 parent 8dff1b7 commit a7ae625

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/cli/main.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ fn runWithWindowsHandleInheritance(gpa: Allocator, exe_path: []const u8, shm_han
597597

598598
// Create command line with handle and size as arguments
599599
const handle_uint = @intFromPtr(shm_handle.fd);
600-
const cmd_line = try std.fmt.allocPrintZ(gpa, "\"{s}\" {} {}", .{ exe_path, handle_uint, shm_handle.size });
600+
const cmd_line = try std.fmt.allocPrint(gpa, "\"{s}\" {} {}\x00", .{ exe_path, handle_uint, shm_handle.size });
601601
defer gpa.free(cmd_line);
602602
const cmd_line_w = try std.unicode.utf8ToUtf16LeAllocZ(gpa, cmd_line);
603603
defer gpa.free(cmd_line_w);

src/ipc/platform.zig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,17 @@ pub fn createMapping(size: usize) SharedMemoryError!Handle {
198198
};
199199
defer std.heap.page_allocator.free(random_name);
200200

201-
const shm_name = std.fmt.allocPrintZ(
201+
const shm_name = std.fmt.allocPrint(
202202
std.heap.page_allocator,
203-
"{s}",
203+
"{s}\x00",
204204
.{random_name},
205205
) catch {
206206
return error.OutOfMemory;
207207
};
208208
defer std.heap.page_allocator.free(shm_name);
209-
209+
const shm_name_null_terminated = shm_name[0 .. shm_name.len - 1 :0];
210210
const fd = posix.shm_open(
211-
shm_name.ptr,
211+
shm_name_null_terminated,
212212
@as(u32, @bitCast(std.posix.O{ .ACCMODE = .RDWR, .CREAT = true, .EXCL = true })),
213213
0o600,
214214
);
@@ -218,7 +218,7 @@ pub fn createMapping(size: usize) SharedMemoryError!Handle {
218218
}
219219

220220
// Immediately unlink so it gets cleaned up when all references are closed
221-
_ = posix.shm_unlink(shm_name.ptr);
221+
_ = posix.shm_unlink(shm_name_null_terminated);
222222

223223
// Set the size of the shared memory
224224
std.posix.ftruncate(fd, size) catch {
@@ -254,13 +254,13 @@ pub fn openMapping(allocator: std.mem.Allocator, name: []const u8) SharedMemoryE
254254
return handle.?;
255255
},
256256
.macos, .freebsd, .openbsd, .netbsd => {
257-
const shm_name = std.fmt.allocPrintZ(allocator, "/{s}", .{name}) catch {
257+
const shm_name = std.fmt.allocPrint(allocator, "/{s}\x00", .{name}) catch {
258258
return error.OutOfMemory;
259259
};
260260
defer allocator.free(shm_name);
261-
261+
const shm_name_null_terminated = shm_name[0 .. shm_name.len - 1 :0];
262262
const fd = posix.shm_open(
263-
shm_name.ptr,
263+
shm_name_null_terminated,
264264
@as(u32, @bitCast(std.posix.O{ .ACCMODE = .RDWR })),
265265
0,
266266
);

0 commit comments

Comments
 (0)