#I have a bug, that causes recursion in allocator?

1 messages · Page 1 of 1 (latest)

quaint mulch
#

or at least it looks like it in the stacktrace?

pub const Writer = struct {
    out: std.ArrayList(u8),
    a: std.mem.Allocator,
    pub fn write_u32(self:*@This(), v: u32) void {
        var new = self.out.addManyAsSlice(self.a, 4) catch unreachable;
        new[0] = @truncate(v);
        new[1] = @truncate(v >> 8);
        new[2] = @truncate(v >> 16);
        new[3] = @truncate(v >> 24);
    }
};

Error:

thread 19740 panic: integer overflow
0.16.0\lib\std\heap\ArenaAllocator.zig:357:33: 0x7ff7e4634854 in alloc (CffEditor_zcu.obj)
const alignable = n + alignment.toByteUnits() - 1;
^
0.16.0\lib\std\mem\Allocator.zig:142: 0x7ff7e3d0a193 in rawAlloc (CffEditor_zcu.obj)
return a.vtable.alloc(a.ptr, len, alignment, ret_addr);

0.16.0\lib\std\mem\Allocator.zig:142: 0x7ff7e3d0a193 in rawAlloc (CffEditor_zcu.obj)
return a.vtable.alloc(a.ptr, len, alignment, ret_addr);
...

0.16.0\lib\std\mem\Allocator.zig:300:35: 0x7ff7e3d0a193 in allocBytesWithAlignment__anon_13643 (CffEditor_zcu.obj)
const byte_ptr = self.rawAlloc(byte_count, alignment, return_address) orelse return error.OutOfMemory;
^
0.16.0\lib\std\mem\Allocator.zig:286:40: 0x7ff7e3d09e71 in allocWithSizeAndAlignment__anon_13633 (CffEditor_zcu.obj)
return self.allocBytesWithAlignment(alignment, byte_count, return_address);
^
0.16.0\lib\std\mem\Allocator.zig:274: 0x7ff7e3d7fe9a in allocAdvancedWithRetAddr (CffEditor_zcu.obj)
const ptr: [*]align(a.toByteUnits()) T = @ptrCast(try self.allocWithSizeAndAlignment(@sizeOf(T), a, n, return_address));

0.16.0\lib\std\mem\Allocator.zig:274: 0x7ff7e3d7fe9a in allocAdvancedWithRetAddr (CffEditor_zcu.obj)
const ptr: [*]align(a.toByteUnits()) T = @ptrCast(try self.allocWithSizeAndAlignment(@sizeOf(T), a, n, return_address));
...

#

0.16.0\lib\std\mem\Allocator.zig:262:41: 0x7ff7e3d7fe9a in alignedAlloc__anon_37935 (CffEditor_zcu.obj)
return self.allocAdvancedWithRetAddr(T, alignment, n, @returnAddress());
^
0.16.0\lib\std\array_list.zig:1235:56: 0x7ff7e4030e83 in ensureTotalCapacityPrecise (CffEditor_zcu.obj)
const new_memory = try gpa.alignedAlloc(T, alignment, new_capacity);
^
0.16.0\lib\std\array_list.zig:1211:51: 0x7ff7e4030886 in ensureTotalCapacity (CffEditor_zcu.obj)
return self.ensureTotalCapacityPrecise(gpa, growCapacity(new_capacity));
^
0.16.0\lib\std\array_list.zig:1112:41: 0x7ff7e44400a6 in resize (CffEditor_zcu.obj)
try self.ensureTotalCapacity(gpa, new_len);
^
0.16.0\lib\std\array_list.zig:1341:28: 0x7ff7e443fd09 in addManyAsSlice (CffEditor_zcu.obj)
try self.resize(gpa, try addOrOom(self.items.len, n));
^
src\cff\writer.zig:36:42: 0x7ff7e445461c in write_u32 (CffEditor_zcu.obj)
var new = self.out.addManyAsSlice(self.a, 4) catch unreachable;
^
src\root.zig:43:27: 0x7ff7e443ebf1 in toPakBytes (CffEditor_zcu.obj)
headerWriter.write_u32(fileCount); // file count
^

#

Am I calling wrong function?