Skip to content

Commit

Permalink
align cand_scores
Browse files Browse the repository at this point in the history
align cand_scores to prevent data aborts on architectures with alignment
restrictions
  • Loading branch information
hefloryd committed Jul 14, 2015
1 parent 7236147 commit 7c54937
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/spiffs_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 7c54937

Please sign in to comment.