Skip to content

Commit 0cc34e0

Browse files
committed
- moved the null-pointer check in transfer(buf, count) to start of the function
1 parent 32446a5 commit 0cc34e0

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

libraries/SPI/SPI.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -227,24 +227,23 @@ uint16_t ArduinoSPI::transfer16(uint16_t data)
227227

228228
void ArduinoSPI::transfer(void *buf, size_t count)
229229
{
230-
if (_is_sci) {
231-
_spi_cb_event[_cb_event_idx] = SPI_EVENT_TRANSFER_ABORTED;
230+
if (buf != NULL) {
231+
if (_is_sci) {
232+
_spi_cb_event[_cb_event_idx] = SPI_EVENT_TRANSFER_ABORTED;
232233

233-
_write_then_read(&_spi_sci_ctrl, buf, buf, count, SPI_BIT_WIDTH_8_BITS);
234+
_write_then_read(&_spi_sci_ctrl, buf, buf, count, SPI_BIT_WIDTH_8_BITS);
234235

235-
for (auto const start = millis();
236-
(SPI_EVENT_TRANSFER_COMPLETE != _spi_cb_event[_cb_event_idx]) && (millis() - start < 1000); )
237-
{
238-
__NOP();
239-
}
240-
if (SPI_EVENT_TRANSFER_ABORTED == _spi_cb_event[_cb_event_idx])
241-
{
242-
end();
236+
for (auto const start = millis();
237+
(SPI_EVENT_TRANSFER_COMPLETE != _spi_cb_event[_cb_event_idx]) && (millis() - start < 1000); )
238+
{
239+
__NOP();
240+
}
241+
if (SPI_EVENT_TRANSFER_ABORTED == _spi_cb_event[_cb_event_idx])
242+
{
243+
end();
244+
}
243245
}
244-
}
245-
else
246-
{
247-
if (buf != NULL) {
246+
else {
248247
uint32_t *buffer32 = (uint32_t *) buf;
249248
size_t index_rx = 0;
250249
size_t index_tx = 0;

0 commit comments

Comments
 (0)