We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linux, zig 0.7.1 release.
mkdir segfault && cd segfault zig init-exe
paste the following in src/main.zig:
const std = @import("std"); const ArgIterator = std.process.ArgIterator; pub fn main() !void { var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); defer arena.deinit(); var alloc = arena.allocator; //var alloc = &arena.allocator; var args = ArgIterator.init(); defer args.deinit(); while (args.next(&alloc)) |arg| { //while (args.next(alloc)) |arg| { } }
zig build run
umaru% zig build run Segmentation fault at address 0x0 /usr/lib/zig/std/special/c.zig:188:25: 0x234ec0 in memset (c) dest.?[index] = c; ^ /usr/lib/zig/std/mem/Allocator.zig:186:41: 0x21df0a in std.mem.Allocator.alloc (membug) return self.allocAdvancedWithRetAddr(T, null, n, .exact, @returnAddress()); ^ /usr/lib/zig/std/mem/Allocator.zig:469:40: 0x2325ab in std.mem.Allocator.dupeZ (membug) const new_buf = try allocator.alloc(T, m.len + 1); ^ /usr/lib/zig/std/process.zig:444:35: 0x232292 in std.process.ArgIterator.next (membug) return allocator.dupeZ(u8, self.inner.next() orelse return null); ^ /shareddata/share/prog/zig/membug/src/main.zig:12:21: 0x22b167 in main (membug) while (args.next(&alloc)) |arg| { ^ /usr/lib/zig/std/start.zig:334:37: 0x204d5d in std.start.posixCallMainAndExit (membug) const result = root.main() catch |err| { ^ /usr/lib/zig/std/start.zig:162:5: 0x204a92 in std.start._start (membug) @call(.{ .modifier = .never_inline }, posixCallMainAndExit, .{}); ^ The following command terminated unexpectedly: cd /shareddata/share/prog/zig/membug && /shareddata/share/prog/zig/membug/zig-cache/bin/membug error: the following build command failed with exit code 1: /shareddata/share/prog/zig/membug/zig-cache/o/ef07146b27f2cb074c4695700607b8a9/build /usr/bin/zig /shareddata/share/prog/zig/membug /shareddata/share/prog/zig/membug/zig-cache /home/jojolepro/.cache/zig run
If using the commented lines instead of the uncommented ones, the bug is not present.
I'm very new to zig, so I might be doing something wrong? This seems like an error that the compiler should warn about? Thanks!
The text was updated successfully, but these errors were encountered:
You're copying the allocator interface out of the arena allocator leading to bad pointer dereferences, see #591.
Sorry, something went wrong.
aaah that explains. thank you!
No branches or pull requests
System
Linux, zig 0.7.1 release.
Reproduce
mkdir segfault && cd segfault
zig init-exe
paste the following in src/main.zig:
zig build run
Result
If using the commented lines instead of the uncommented ones, the bug is not present.
I'm very new to zig, so I might be doing something wrong? This seems like an error that the compiler should warn about? Thanks!
The text was updated successfully, but these errors were encountered: