This is a bit of a strange problem, I'm not sure why this happens but the following code will crash when run in debug mode but not when in release mode.
use std::error::Error;
use xcb::{
x::{EventMask, InternAtom, SendEventDest, Timestamp, Window},
Connection, Xid,
};
fn main() -> Result<(), Box<dyn Error>> {
let (connection, _) = Connection::connect(None)?;
let setup = connection.get_setup();
let screen = setup.roots().next().unwrap();
let window: Window = connection.generate_id();
let time: Timestamp = 0;
let manager_atom = connection
.wait_for_reply(connection.send_request(&InternAtom {
only_if_exists: false,
name: "MANAGER".as_bytes(),
}))
.unwrap()
.atom();
let selection = connection
.wait_for_reply(connection.send_request(&InternAtom {
only_if_exists: false,
name: "_NET_SYSTEM_TRAY_S0".as_bytes(),
}))
.unwrap()
.atom();
let client_event = xcb::x::ClientMessageEvent::new(
screen.root(),
manager_atom,
xcb::x::ClientMessageData::Data32([
time,
selection.resource_id(),
window.resource_id(),
0,
0,
]),
);
connection.send_and_check_request(&xcb::x::SendEvent {
propagate: false,
destination: SendEventDest::Window(screen.root()),
event_mask: EventMask::STRUCTURE_NOTIFY,
event: &client_event,
})?;
connection.flush()?;
Ok(())
}
This is the smallest example I could recreate.
Looking at the backtrace it looks like the problem is caused by SendEventDest::serialize.
thread 'main' panicked at 'misaligned pointer dereference: address must be a multiple of 0x4 but is 0x7ffd564a2d5f', /home/matteo/progetti/rust/minimum_bug/target/debug/build/xcb-47cb19d8d0ed61c5/out/xproto.rs:8103:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'panic in a function that cannot unwind', library/core/src/panicking.rs:126:5
stack backtrace:
0: 0x55d025b4138a - std::backtrace_rs::backtrace::libunwind::trace::h9a6b80bbf328ba5d
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
1: 0x55d025b4138a - std::backtrace_rs::backtrace::trace_unsynchronized::hd162ec543a11886b
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
2: 0x55d025b4138a - std::sys_common::backtrace::_print_fmt::h78a5099be12f51a6
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:65:5
3: 0x55d025b4138a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::ha1c5390454d74f71
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:44:22
4: 0x55d025b5b4df - core::fmt::write::h9ffde816c577717b
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/fmt/mod.rs:1254:17
5: 0x55d025b3f135 - std::io::Write::write_fmt::h88186074961638e4
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/io/mod.rs:1698:15
6: 0x55d025b41155 - std::sys_common::backtrace::_print::h184198273ed08d59
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:47:5
7: 0x55d025b41155 - std::sys_common::backtrace::print::h1b4d8e7add699453
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:34:9
8: 0x55d025b426de - std::panicking::default_hook::{{closure}}::h393bcea75423915a
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:269:22
9: 0x55d025b42485 - std::panicking::default_hook::h48c64f31d8b3fd03
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:288:9
10: 0x55d025b42c3e - std::panicking::rust_panic_with_hook::hafdc493a79370062
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:691:13
11: 0x55d025b42af2 - std::panicking::begin_panic_handler::{{closure}}::h0a64bc82e36bedc7
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:580:13
12: 0x55d025b417f6 - std::sys_common::backtrace::__rust_end_short_backtrace::hc203444fb7416a16
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:150:18
13: 0x55d025b42892 - rust_begin_unwind
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:578:5
14: 0x55d025b19f73 - core::panicking::panic_nounwind_fmt::hd4fea0bcbbc9daea
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:96:14
15: 0x55d025b1a021 - core::panicking::panic_nounwind::h07db722b03cd9dbd
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:126:5
16: 0x55d025b1a1b3 - core::panicking::panic_cannot_unwind::hfaa00866a3a05433
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:188:5
17: 0x55d025b1f65a - xcb::xproto::SendEventDest::serialize::h3a216a8f6af12c8c
at /home/matteo/progetti/rust/minimum_bug/target/debug/build/xcb-47cb19d8d0ed61c5/out/xproto.rs:8100:5
18: 0x55d025b1a881 - <xcb::xproto::SendEvent<E> as xcb::base::RawRequest>::raw_request::h11a5fc5ab7b758a2
at /home/matteo/progetti/rust/minimum_bug/target/debug/build/xcb-47cb19d8d0ed61c5/out/xproto.rs:14645:9
19: 0x55d025b1b983 - xcb::base::Connection::send_request_checked::h7ebd81ddbce0d727
at /home/matteo/.cargo/registry/src/index.crates.io-6f17d22bba15001f/xcb-1.2.1/src/base.rs:1442:51
20: 0x55d025b1b9d7 - xcb::base::Connection::send_and_check_request::h554ad02d77fc8c68
at /home/matteo/.cargo/registry/src/index.crates.io-6f17d22bba15001f/xcb-1.2.1/src/base.rs:1533:28
21: 0x55d025b1c4bf - minimum_bug::main::heaf743f21c98fe7d
at /home/matteo/progetti/rust/minimum_bug/src/main.rs:39:5
22: 0x55d025b1ab2b - core::ops::function::FnOnce::call_once::hc485ca90f17576c3
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ops/function.rs:250:5
23: 0x55d025b1ac2e - std::sys_common::backtrace::__rust_begin_short_backtrace::h2ee1a3b1a792bf8f
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:134:18
24: 0x55d025b1be51 - std::rt::lang_start::{{closure}}::h5ca2bd6164ad8eb3
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/rt.rs:166:18
25: 0x55d025b3d0ae - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hb1327dc2ef3fecdf
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ops/function.rs:287:13
26: 0x55d025b3d0ae - std::panicking::try::do_call::h4044173225fe83dd
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:485:40
27: 0x55d025b3d0ae - std::panicking::try::hd8a722c09d156a53
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:449:19
28: 0x55d025b3d0ae - std::panic::catch_unwind::hd2ca07971cf0119b
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panic.rs:140:14
29: 0x55d025b3d0ae - std::rt::lang_start_internal::{{closure}}::h26d89d595cf47b70
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/rt.rs:148:48
30: 0x55d025b3d0ae - std::panicking::try::do_call::hf47aa1aa005e5f1a
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:485:40
31: 0x55d025b3d0ae - std::panicking::try::h73d246b2423eaf4e
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:449:19
32: 0x55d025b3d0ae - std::panic::catch_unwind::hbaaeae8f1b2f9915
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panic.rs:140:14
33: 0x55d025b3d0ae - std::rt::lang_start_internal::h76f3e81e6b8f13f9
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/rt.rs:148:20
34: 0x55d025b1be2a - std::rt::lang_start::h5450807fb477364b
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/rt.rs:165:17
35: 0x55d025b1c66e - main
36: 0x7f8afd429d90 - __libc_start_call_main
at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
37: 0x7f8afd429e40 - __libc_start_main_impl
at ./csu/../csu/libc-start.c:392:3
38: 0x55d025b1a5a5 - _start
39: 0x0 - <unknown>
thread caused non-unwinding panic. aborting.
This is a bit of a strange problem, I'm not sure why this happens but the following code will crash when run in debug mode but not when in release mode.
This is the smallest example I could recreate. Looking at the backtrace it looks like the problem is caused by
SendEventDest::serialize
.