From 7c5493732da5b43e09fa4d81be6c8a713c2be79c Mon Sep 17 00:00:00 2001 From: Hans-Erik Floryd Date: Tue, 14 Jul 2015 15:16:33 +0200 Subject: [PATCH] align cand_scores align cand_scores to prevent data aborts on architectures with alignment restrictions --- src/spiffs_gc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/spiffs_gc.c b/src/spiffs_gc.c index 5752e70..b60d7d3 100644 --- a/src/spiffs_gc.c +++ b/src/spiffs_gc.c @@ -249,10 +249,15 @@ s32_t spiffs_gc_find_candidate( memset(fs->work, 0xff, SPIFFS_CFG_LOG_PAGE_SZ(fs)); // divide up work area into block indices and scores - // todo alignment? spiffs_block_ix *cand_blocks = (spiffs_block_ix *)fs->work; s32_t *cand_scores = (s32_t *)(fs->work + max_candidates * sizeof(spiffs_block_ix)); + // align cand_scores on s32_t boundary +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpointer-to-int-cast" + cand_scores = (s32_t*)(((u32_t)cand_scores + sizeof(s32_t) - 1) & ~(sizeof(s32_t) - 1)); +#pragma GCC diagnostic pop + *block_candidates = cand_blocks; int entries_per_page = (SPIFFS_CFG_LOG_PAGE_SZ(fs) / sizeof(spiffs_obj_id));