one-based indexing enums is not cool

Fixes possible out of array bounds introduced in 5af710ff73
This commit is contained in:
Andrey Gusakov 2024-03-02 23:38:46 +03:00 committed by rusefillc
parent 462a1c8c0d
commit de96d8ba06
5 changed files with 10 additions and 5 deletions

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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