My config file lib SIGSEGVs when running example, also, is there a better way to do binary config format parsing without raw pointers?

Using raw pointers here feels unnecessary. Is there any reason why you don't want to use normal methods on &[u8] like slicing or methods like u32::from_le_bytes()?

I ran your program under gdb and it gave the following backtrace:

#0  0x00005555b6ec3cc0 in ?? ()
#1  0x000000000000000b in ?? ()
#2  0x00007fffffffb738 in ?? ()
#3  0x0000000000000070 in ?? ()
#4  0x000055555558954d in core::intrinsics::copy_nonoverlapping<u8> () at /rustc/bfe15646761a75f0259e204cab071565eed2b1e5/library/core/src/intrinsics.rs:2083
#5  alloc::vec::Vec::append_elements<u8, alloc::alloc::Global> () at library/alloc/src/vec/mod.rs:1798
#6  alloc::vec::spec_extend::{impl#4}::spec_extend<u8, alloc::alloc::Global> () at library/alloc/src/vec/spec_extend.rs:85
#7  alloc::vec::Vec::extend_from_slice<u8, alloc::alloc::Global> () at library/alloc/src/vec/mod.rs:2229
#8  alloc::string::String::push_str () at library/alloc/src/string.rs:850
#9  alloc::string::{impl#63}::write_str () at library/alloc/src/string.rs:2727
#10 core::fmt::{impl#0}::write_str<alloc::string::String> () at /rustc/bfe15646761a75f0259e204cab071565eed2b1e5/library/core/src/fmt/mod.rs:193
#11 0x00005555556b69c2 in core::fmt::run () at library/core/src/fmt/mod.rs:1216
#12 core::fmt::write () at library/core/src/fmt/mod.rs:1184
#13 0x00005555555884bc in core::fmt::Write::write_fmt<alloc::string::String> ()
    at /rustc/bfe15646761a75f0259e204cab071565eed2b1e5/library/core/src/fmt/mod.rs:186
#14 alloc::fmt::format () at library/alloc/src/fmt.rs:597
#15 0x00005555556c9807 in formulae::Node::from_bytes (node_type=0x5555558194b1, next=0x7fffffffcb78, data_end=0x5555558194eb) at src/lib.rs:115
#16 0x00005555556c996a in formulae::Node::from_bytes (node_type=0x555555819488, next=0x7fffffffcb78, data_end=0x5555558194eb) at src/lib.rs:106
#17 0x00005555556caac8 in formulae::Root::from_bytes (data=...) at src/lib.rs:182
#18 0x00005555555816a6 in ftool::main () at examples/ftool.rs:60

Looks like the node_type variable on line 103 (stack frame #16) doesn't contain what you think it does because we pass it into Node::from_bytes() which then blows up when it reads the value while printing the "Unimplemented Node type" error message.

1 Like