zig

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

commit f0482c95d2c0ed05b6f8ee2826e4fc11982410b4 (tree)
parent 23ac4dd87b740012ba33e8ab2ea6fb25c04b6268
Author: kcbanner <kcbanner@gmail.com>
Date:   Sat, 15 Apr 2023 23:23:29 -0400

DynLib.lookup: cast the pointer to the correct alignment

Diffstat:
Mlib/std/dynamic_library.zig | 4++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/std/dynamic_library.zig b/lib/std/dynamic_library.zig @@ -348,7 +348,7 @@ pub const WindowsDynLib = struct { pub fn lookup(self: *WindowsDynLib, comptime T: type, name: [:0]const u8) ?T { if (windows.kernel32.GetProcAddress(self.dll, name.ptr)) |addr| { - return @ptrCast(T, addr); + return @ptrCast(T, @alignCast(@alignOf(@typeInfo(T).Pointer.child), addr)); } else { return null; } @@ -382,7 +382,7 @@ pub const DlDynlib = struct { // dlsym (and other dl-functions) secretly take shadow parameter - return address on stack // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66826 if (@call(.never_tail, system.dlsym, .{ self.handle, name.ptr })) |symbol| { - return @ptrCast(T, symbol); + return @ptrCast(T, @alignCast(@alignOf(@typeInfo(T).Pointer.child), symbol)); } else { return null; }