fix: "array out of bounds" error leading to memory corruption

Fix description
----------------
add missing checks on the index of nor_flash -> lx_nor_flash_extended_cache[i]

Fixes Issue#58

Signed-off-by: Haithem Rahmani <haithem.rahmani@st.com>
This commit is contained in:
Haithem Rahmani
2025-10-22 16:14:04 +01:00
parent 04e385f3d5
commit 7d1ef20acf
@@ -290,7 +290,7 @@ ULONG block_word;
/* Loop through the memory supplied and assign to cache entries. */
i = 0;
while (cache_size >= LX_NOR_SECTOR_SIZE)
while ((cache_size >= LX_NOR_SECTOR_SIZE) && (i < LX_NOR_EXTENDED_CACHE_SIZE))
{
/* Setup this cache entry. */
@@ -309,7 +309,7 @@ ULONG block_word;
}
/* Save the number of cache entries. */
if(i > LX_NOR_EXTENDED_CACHE_SIZE)
if(i == LX_NOR_EXTENDED_CACHE_SIZE)
{
nor_flash -> lx_nor_flash_extended_cache_entries = LX_NOR_EXTENDED_CACHE_SIZE;