Skip to content

Commit 878d7ac

Browse files
committed
Fix divide by zero, case when heap is 100% allocated.
1 parent 3eea82a commit 878d7ac

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

cores/esp8266/Esp-frag.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@ void EspClass::getHeapStats(uint32_t* hfree, uint16_t* hmax, uint8_t* hfrag)
3434
*hfree = (uint32_t)ummHeapInfo.freeBlocks * umm_block_size();
3535
if (hmax)
3636
*hmax = umm_free_blocks_to_free_space(ummHeapInfo.maxFreeContiguousBlocks);
37-
if (hfrag)
37+
if (hfrag) {
38+
if (ummHeapInfo.freeBlocks) {
3839
*hfrag = 100 - (sqrt32(ummHeapInfo.freeBlocksSquared) * 100) / ummHeapInfo.freeBlocks;
40+
} else {
41+
*hfrag = 0;
42+
}
43+
}
3944

4045
}
4146

0 commit comments

Comments
 (0)