Skip to content
Prev Previous commit
Next Next commit
Fix divide by zero, case when heap is 100% allocated.
  • Loading branch information
mhightower83 committed May 29, 2020
commit 878d7ac7f211b68ed2f0dc55cc79fbe6ce8271f6
7 changes: 6 additions & 1 deletion cores/esp8266/Esp-frag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ void EspClass::getHeapStats(uint32_t* hfree, uint16_t* hmax, uint8_t* hfrag)
*hfree = (uint32_t)ummHeapInfo.freeBlocks * umm_block_size();
if (hmax)
*hmax = umm_free_blocks_to_free_space(ummHeapInfo.maxFreeContiguousBlocks);
if (hfrag)
if (hfrag) {
if (ummHeapInfo.freeBlocks) {
*hfrag = 100 - (sqrt32(ummHeapInfo.freeBlocksSquared) * 100) / ummHeapInfo.freeBlocks;
} else {
*hfrag = 0;
}
}

}

Expand Down