mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
std.mem.Allocator: do not return undefined pointers from create
Closes #13517
This commit is contained in:
parent
11c64bfe6e
commit
b6b3462796
@ -167,7 +167,7 @@ pub inline fn rawFree(self: Allocator, buf: []u8, buf_align: u29, ret_addr: usiz
|
||||
/// Returns a pointer to undefined memory.
|
||||
/// Call `destroy` with the result to free the memory.
|
||||
pub fn create(self: Allocator, comptime T: type) Error!*T {
|
||||
if (@sizeOf(T) == 0) return @as(*T, undefined);
|
||||
if (@sizeOf(T) == 0) return @intToPtr(*T, std.math.maxInt(usize));
|
||||
const slice = try self.allocAdvancedWithRetAddr(T, null, 1, .exact, @returnAddress());
|
||||
return &slice[0];
|
||||
}
|
||||
|
||||
@ -18754,7 +18754,7 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
|
||||
const addr = val.toUnsignedInt(target);
|
||||
if (!ptr_ty.isAllowzeroPtr() and addr == 0)
|
||||
return sema.fail(block, operand_src, "pointer type '{}' does not allow address zero", .{ptr_ty.fmt(sema.mod)});
|
||||
if (addr != 0 and addr % ptr_align != 0)
|
||||
if (addr != 0 and ptr_align != 0 and addr % ptr_align != 0)
|
||||
return sema.fail(block, operand_src, "pointer type '{}' requires aligned address", .{ptr_ty.fmt(sema.mod)});
|
||||
|
||||
const val_payload = try sema.arena.create(Value.Payload.U64);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user