Skip to content

Commit

Permalink
prevent _settings[] array from being written to beyond the end of the…
Browse files Browse the repository at this point in the history
… array

check for #if BOARD_NR_SPI >= 1 and 2 as is done for >= 3 to insure _settings[] array is not written beyond the end.
  • Loading branch information
mitchmitchell authored Feb 8, 2019
1 parent 4865add commit 096facf
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions STM32F4/libraries/SPI/src/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ SPIClass::SPIClass(uint32 spi_num) {
// SPI2: 1 / 0 / 3 - 1 / 0 / 4
// SPI3: 1 / 0 / 0 (2) - 1 / 0 / 5 (7)
/*****************************************************************************/
#if BOARD_NR_SPI >= 1
_settings[0].spi_d = SPI1;
_settings[0].clockDivider = determine_baud_rate(_settings[0].spi_d, _settings[0].clock);
#ifdef SPI_DMA
Expand All @@ -132,6 +133,8 @@ SPIClass::SPIClass(uint32 spi_num) {
_settings[0].spiRxDmaStream = DMA_STREAM0; // alternative: DMA_STREAM2
_settings[0].spiTxDmaStream = DMA_STREAM3; // alternative: DMA_STREAM5
#endif
#endif
#if BOARD_NR_SPI >= 2
_settings[1].spi_d = SPI2;
_settings[1].clockDivider = determine_baud_rate(_settings[1].spi_d, _settings[1].clock);
#ifdef SPI_DMA
Expand All @@ -140,6 +143,7 @@ SPIClass::SPIClass(uint32 spi_num) {
_settings[1].spiRxDmaStream = DMA_STREAM3; // alternative: -
_settings[1].spiTxDmaStream = DMA_STREAM4; // alternative: -
#endif
#endif
#if BOARD_NR_SPI >= 3
_settings[2].spi_d = SPI3;
_settings[2].clockDivider = determine_baud_rate(_settings[2].spi_d, _settings[2].clock);
Expand Down

0 comments on commit 096facf

Please sign in to comment.