embassy-rs / nrf-softdevice

Apache License 2.0
256 stars 76 forks source link

fix(gatt_traits): fixed gatt server crashing at writes to [u8; N] with len < N #178

Closed Yandrik closed 1 year ago

Yandrik commented 1 year ago
#[characteristic(uuid = "...", write)]
some_characteristic: [u8; 4]

will fail whenever the written value is smaller than four octets, and it will not do so gracefully, but instead panic directly. This PR fixes this problem. New behavior:

Dirbaio commented 1 year ago

btw there's the same issue with the primitives. For example for a u32 char, if you write 3 bytes instead of 4.

alexmoon commented 1 year ago

I believe a short write packet will cause the softdevice to overwrite the first N bytes of the characteristic value. To get the value stored by the softdevice for a short write, you need to read the characteristic value instead of using the slice passed to the event.