diff --git a/src/radio/sx126x/radio.c b/src/radio/sx126x/radio.c index c4a40dab8..abe128c08 100644 --- a/src/radio/sx126x/radio.c +++ b/src/radio/sx126x/radio.c @@ -1119,9 +1119,16 @@ void RadioAddRegisterToRetentionList( uint16_t registerAddress ) // Read the address and registers already added to the list SX126xReadRegisters( REG_RETENTION_LIST_BASE_ADDRESS, buffer, 9 ); - const uint8_t nbOfRegisters = buffer[0]; + uint8_t nbOfRegisters = buffer[0]; uint8_t* registerList = &buffer[1]; + // in case more than maximum read -> set to 0 + if(nbOfRegisters > MAX_NB_REG_IN_RETENTION) + { + nbOfRegisters = 0; + buffer[0] = 0; // set also to zero - invalid value was read-out + } + // Check if the register given as parameter is already added to the list for( uint8_t i = 0; i < nbOfRegisters; i++ ) {