-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior
Description
Zig Version
0.16.0-dev.225+0b75a2a1b
Steps to Reproduce and Observed Behavior
const std = @import("std");
const SinglyLinkedList = std.SinglyLinkedList;
pub fn main() !void {
const List = struct {
node: SinglyLinkedList.Node = .{},
};
var list: SinglyLinkedList = .{};
var one: List = .{};
var two: List = .{};
list.prepend(&one.node);
one.node.insertAfter(&two.node);
_ = list.remove(&two.node);
_ = list.remove(&two.node);
}
havelock@pop-os:~/code/scr$ zig run sll_error.zig
thread 134888 panic: attempt to use null value
/home/havelock/bin/zig/lib/std/SinglyLinkedList.zig:94:43: 0x1137b3b in remove (std.zig)
current_elm = current_elm.next.?;
^
/home/havelock/code/scr/sll_error.zig:16:20: 0x11364ff in main (sll_error.zig)
_ = list.remove(&two.node);
^
/home/havelock/bin/zig/lib/std/start.zig:627:37: 0x1136cad in posixCallMainAndExit (std.zig)
const result = root.main() catch |err| {
^
/home/havelock/bin/zig/lib/std/start.zig:232:5: 0x1136421 in _start (std.zig)
asm volatile (switch (native_arch) {
^
???:?:?: 0x0 in ??? (???)
Aborted (core dumped)
Expected Behavior
I would expect the function to return false when the node is not removed, or at the very least avoid crashing.
trolleyman
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior