Skip to content

Commit

Permalink
one-based indexing enums is not cool
Browse files Browse the repository at this point in the history
Fixes possible out of array bounds introduced in 5af710f
  • Loading branch information
dron0gus committed Mar 2, 2024
1 parent 1a5c682 commit 2af67fc
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion firmware/hw_layer/hardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
#endif

#if HAL_USE_SPI
extern bool isSpiInitialized[SPI_TOTAL_COUNT];
/* zero index is SPI_NONE */
extern bool isSpiInitialized[SPI_TOTAL_COUNT + 1];

/**
* Only one consumer can use SPI bus at a given time
Expand Down
3 changes: 2 additions & 1 deletion firmware/hw_layer/ports/at32/at32_spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#include "pch.h"

#if HAL_USE_SPI
bool isSpiInitialized[SPI_TOTAL_COUNT] = { false, false, false, false, false, false };
/* zero index is SPI_NONE */
bool isSpiInitialized[SPI_TOTAL_COUNT + 1] = { true, false, false, false, false, false, false };

struct af_pairs {
brain_pin_e pin;
Expand Down
3 changes: 2 additions & 1 deletion firmware/hw_layer/ports/cypress/mpu_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ void HardFaultVector(void) {
}

#if HAL_USE_SPI || defined(__DOXYGEN__)
bool isSpiInitialized[SPI_TOTAL_COUNT] = { false, false, false, false, false, false };
/* zero index is SPI_NONE */
bool isSpiInitialized[SPI_TOTAL_COUNT + 1] = { true, false, false, false, false, false, false };

static int getSpiAf(SPIDriver *driver) {
#if STM32_SPI_USE_SPI1
Expand Down
3 changes: 2 additions & 1 deletion firmware/hw_layer/ports/kinetis/mpu_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ void HardFaultVector(void) {
}

#if HAL_USE_SPI || defined(__DOXYGEN__)
bool isSpiInitialized[SPI_TOTAL_COUNT] = { false, false, false, false, false, false };
/* zero index is SPI_NONE */
bool isSpiInitialized[SPI_TOTAL_COUNT + 1] = { true, false, false, false, false, false, false };

static int getSpiAf(SPIDriver *driver) {
#if STM32_SPI_USE_SPI1
Expand Down
3 changes: 2 additions & 1 deletion firmware/hw_layer/ports/stm32/stm32_spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#include "pch.h"

#if HAL_USE_SPI
bool isSpiInitialized[SPI_TOTAL_COUNT] = { false, false, false, false, false, false };
/* zero index is SPI_NONE */
bool isSpiInitialized[SPI_TOTAL_COUNT + 1] = { true, false, false, false, false, false, false };

static int getSpiAf(SPIDriver *driver) {
#if STM32_SPI_USE_SPI1
Expand Down

0 comments on commit 2af67fc

Please sign in to comment.