From 1fdd296784621edc93d94442f8ca5237eaad8dbb Mon Sep 17 00:00:00 2001 From: Allen Hill Date: Sun, 5 Jul 2026 19:40:48 -0700 Subject: [PATCH] Ref `shouldACK` in lambda to only set once --- src/avclan/bus.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/avclan/bus.cc b/src/avclan/bus.cc index 74ce893..1dacd76 100644 --- a/src/avclan/bus.cc +++ b/src/avclan/bus.cc @@ -83,7 +83,12 @@ auto Bus::read(uint16_t address, Frame *in, Frame::Print print) -> Error::Read { if (auto rerr = handle.read( &in->peripheral_addr, - [&]() { return !is_muted() && (in->peripheral_addr == address); }); + // Using lambda for delayed evaluation of peripheral_addr field + // deref, which will be written by the time the lambda is evaluated + [&]() { + shouldACK = !is_muted() && (in->peripheral_addr == address); + return shouldACK; + }); rerr == BAD_PARITY) { err.errno = BAD_PERIPHERAL_PARITY; if (print.verbose) { @@ -92,8 +97,6 @@ auto Bus::read(uint16_t address, Frame *in, Frame::Print print) -> Error::Read { goto handle_err; } - shouldACK = !is_muted() && (in->peripheral_addr == address); - if (auto rerr = handle.read(&in->control, shouldACK); rerr == BAD_PARITY) { err.errno = BAD_CONTROL_PARITY;