diff --git a/easyflash/src/ef_log.c b/easyflash/src/ef_log.c index 9d2b8c6..49e9d7c 100644 --- a/easyflash/src/ef_log.c +++ b/easyflash/src/ef_log.c @@ -463,8 +463,7 @@ static uint32_t log_index2addr(size_t index) { if (log_start_addr + index + header_total_offset < log_area_start_addr + LOG_AREA_SIZE) { return log_start_addr + index + header_total_offset; } else { - return log_start_addr + index + header_total_offset - LOG_AREA_SIZE; - + return (log_start_addr + index + header_total_offset) % LOG_AREA_SIZE; } } } @@ -490,8 +489,14 @@ EfErrCode ef_log_read(size_t index, uint32_t *log, size_t size) { return result; } - EF_ASSERT(size % 4 == 0); - EF_ASSERT(index < cur_using_size); + if (size % 4 == 0) { + EF_DEBUG("Error: size must be word aligned."); + return EF_READ_ERR; + } + if (index < cur_using_size) { + EF_DEBUG("Error: index out of ranges, current using size is %d", cur_using_size); + return EF_READ_ERR; + } if (index + size > cur_using_size) { EF_DEBUG("Warning: Log read size out of bound. Cut read size.\n");