Skip to content

Instantly share code, notes, and snippets.

Created December 21, 2020 00:25
What would you like to do?
const std = @import("std");
const builtin = @import("builtin");
const Builder = @import("std").build.Builder;
pub fn build(b: *Builder) void {
const target = b.standardTargetOptions(.{});
const exe = b.addExecutable("huh", "main.zig");
const std = @import("std");
const CAllocator = std.heap.c_allocator;
const out =;
const LogAllocator = &std.heap.loggingAllocator(CAllocator, out);
pub fn main() !void {
var allocator = LogAllocator.allocator;
var new_bytes: []u8 = allocator.alloc(u8, 1) catch unreachable;"len {}", .{new_bytes.len});
turnip /tmp/zig-bug$ zig version
turnip /tmp/zig-bug$ zig build
turnip /tmp/zig-bug$ ./zig-cache/bin/huh
Segmentation fault at address 0x0
/opt/zig/0.7.1/lib/zig/std/heap/logging_allocator.zig:40:49: 0x20386d in std.heap.logging_allocator.LoggingAllocator(,std.os.WriteError,std.fs.file.File.write)).alloc (huh)
const result = self.parent_allocator.allocFn(self.parent_allocator, len, ptr_align, len_align, ra);
/opt/zig/0.7.1/lib/zig/std/mem/Allocator.zig:294:40: 0x2063d1 in std.mem.Allocator.allocAdvancedWithRetAddr (huh)
const byte_slice = try self.allocFn(self, byte_count, a, len_align, return_address);
/opt/zig/0.7.1/lib/zig/std/mem/Allocator.zig:186:41: 0x2047da in std.mem.Allocator.alloc (huh)
return self.allocAdvancedWithRetAddr(T, null, n, .exact, @returnAddress());
/tmp/zig-bug/main.zig:9:40: 0x204737 in main (huh)
var new_bytes: []u8 = allocator.alloc(u8, 1) catch unreachable;
/opt/zig/0.7.1/lib/zig/std/start.zig:344:37: 0x204a85 in std.start.main (huh)
const result = root.main() catch |err| {
zsh: abort (core dumped) ./zig-cache/bin/huh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment