From c51397755910fb4fed4351bbac056642674c1d93 Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Wed, 4 Mar 2020 18:10:45 -0500 Subject: [PATCH] Fix #1400: divide-by-zero error in `lv_mem_monitor` --- src/lv_misc/lv_mem.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lv_misc/lv_mem.c b/src/lv_misc/lv_mem.c index 9e18310fe..10d04886d 100644 --- a/src/lv_misc/lv_mem.c +++ b/src/lv_misc/lv_mem.c @@ -358,8 +358,12 @@ void lv_mem_monitor(lv_mem_monitor_t * mon_p) } mon_p->total_size = LV_MEM_SIZE; mon_p->used_pct = 100 - (100U * mon_p->free_size) / mon_p->total_size; - mon_p->frag_pct = (uint32_t)mon_p->free_biggest_size * 100U / mon_p->free_size; - mon_p->frag_pct = 100 - mon_p->frag_pct; + if(mon_p->free_size > 0) { + mon_p->frag_pct = (uint32_t)mon_p->free_biggest_size * 100U / mon_p->free_size; + mon_p->frag_pct = 100 - mon_p->frag_pct; + } else { + mon_p->frag_pct = 0; /*no fragmentation if all the RAM is used*/ + } #endif }