zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit f841ea77e2cb7ad2ee4ecf993206f0c29d087131 (tree)
parent a2074c1ec31ab553aea4232dfdc760a0442aeddf
Author: Loris Cro <kappaloris@gmail.com>
Date:   Fri,  2 Oct 2020 19:33:14 +0200

make symlink buffer null-terminated

Signed-off-by: Loris Cro <kappaloris@gmail.com>

Diffstat:
Mlib/std/c/darwin.zig | 2+-
Mlib/std/fs.zig | 4++--
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig @@ -12,7 +12,7 @@ usingnamespace @import("../os/bits.zig"); extern "c" fn __error() *c_int; pub extern "c" fn NSVersionOfRunTimeLibrary(library_name: [*:0]const u8) u32; -pub extern "c" fn _NSGetExecutablePath(buf: [*]u8, bufsize: *u32) c_int; +pub extern "c" fn _NSGetExecutablePath(buf: [*:0]u8, bufsize: *u32) c_int; pub extern "c" fn _dyld_image_count() u32; pub extern "c" fn _dyld_get_image_header(image_index: u32) ?*mach_header; pub extern "c" fn _dyld_get_image_vmaddr_slide(image_index: u32) usize; diff --git a/lib/std/fs.zig b/lib/std/fs.zig @@ -2192,13 +2192,13 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 { if (is_darwin) { // Note that _NSGetExecutablePath() will return "a path" to // the executable not a "real path" to the executable. - var symlink_path_buf: [MAX_PATH_BYTES]u8 = undefined; + var symlink_path_buf: [MAX_PATH_BYTES:0]u8 = undefined; var u32_len: u32 = MAX_PATH_BYTES; const rc = std.c._NSGetExecutablePath(&symlink_path_buf, &u32_len); if (rc != 0) return error.NameTooLong; var real_path_buf: [MAX_PATH_BYTES]u8 = undefined; - const real_path = try std.os.realpathZ(@ptrCast([*:0]u8, &symlink_path_buf), &real_path_buf); + const real_path = try std.os.realpathZ(&symlink_path_buf, &real_path_buf); if (real_path.len > out_buffer.len) return error.NameTooLong; std.mem.copy(u8, out_buffer, real_path); return out_buffer[0..real_path.len];