Skip to content

Commit 883680c

Browse files
lulfhargoniX
authored andcommitted
Consistent buffer length check behavior
1 parent 9ecdbb8 commit 883680c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

nrf-hal-common/src/uarte.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ where
169169
/// The buffer must have a length of at most 255 bytes on the nRF52832
170170
/// and at most 65535 bytes on the nRF52840.
171171
pub fn write(&mut self, tx_buffer: &[u8]) -> Result<(), Error> {
172+
if tx_buffer.len() == 0 {
173+
return Err(Error::TxBufferTooSmall);
174+
}
175+
172176
if tx_buffer.len() > EASY_DMA_SIZE {
173177
return Err(Error::TxBufferTooLong);
174178
}
@@ -364,6 +368,10 @@ fn stop_write(uarte: &uarte0::RegisterBlock) {
364368
/// Start a UARTE read transaction by setting the control
365369
/// values and triggering a read task.
366370
fn start_read(uarte: &uarte0::RegisterBlock, rx_buffer: &mut [u8]) -> Result<(), Error> {
371+
if rx_buffer.len() == 0 {
372+
return Err(Error::RxBufferTooSmall);
373+
}
374+
367375
if rx_buffer.len() > EASY_DMA_SIZE {
368376
return Err(Error::RxBufferTooLong);
369377
}

0 commit comments

Comments
 (0)