Skip to content

Commit 8688eb6

Browse files
committed
Consistent buffer length check behavior
1 parent cf11f38 commit 8688eb6

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
@@ -105,6 +105,10 @@ where
105105
/// The buffer must have a length of at most 255 bytes on the nRF52832
106106
/// and at most 65535 bytes on the nRF52840.
107107
pub fn write(&mut self, tx_buffer: &[u8]) -> Result<(), Error> {
108+
if tx_buffer.len() == 0 {
109+
return Err(Error::TxBufferTooSmall);
110+
}
111+
108112
if tx_buffer.len() > EASY_DMA_SIZE {
109113
return Err(Error::TxBufferTooLong);
110114
}
@@ -327,6 +331,10 @@ fn stop_write(uarte: &uarte0::RegisterBlock) {
327331
/// Start a UARTE read transaction by setting the control
328332
/// values and triggering a read task.
329333
fn start_read(uarte: &uarte0::RegisterBlock, rx_buffer: &mut [u8]) -> Result<(), Error> {
334+
if rx_buffer.len() == 0 {
335+
return Err(Error::RxBufferTooSmall);
336+
}
337+
330338
if rx_buffer.len() > EASY_DMA_SIZE {
331339
return Err(Error::RxBufferTooLong);
332340
}

0 commit comments

Comments
 (0)