Skip to content

Instantly share code, notes, and snippets.

@donpdonp
Created December 21, 2020 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donpdonp/cdc31dedb5c5ce77671c938e8c9f2c3a to your computer and use it in GitHub Desktop.
Save donpdonp/cdc31dedb5c5ce77671c938e8c9f2c3a to your computer and use it in GitHub Desktop.
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");
exe.setTarget(target);
exe.linkSystemLibrary("c");
exe.install();
}
const std = @import("std");
const CAllocator = std.heap.c_allocator;
const out = std.io.getStdOut().outStream();
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;
std.log.info("len {}", .{new_bytes.len});
}
turnip /tmp/zig-bug$ zig version
0.7.1+e93cb2254
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.io.writer.Writer(std.fs.file.File,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