diff --git a/CHANGELOG.md b/CHANGELOG.md index b2bfed4380..fc8f5f789a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Bugfixes: * Fixed building with dconf enabled but gio disabled (`-DENABLE_GIO=OFF`). (General) +* Fixed division by zero when calculating disk I/O rates over a sub-millisecond sampling interval. (Top) # 2.72.0 diff --git a/src/detection/top/top.c b/src/detection/top/top.c index 9ff753336d..ca663bc8eb 100644 --- a/src/detection/top/top.c +++ b/src/detection/top/top.c @@ -147,8 +147,8 @@ const char* ffDetectTopProcesses(FFTopOptions* options, FFlist* result) { FFTopProcessResult* item = FF_LIST_ADD(FFTopProcessResult, *result); item->pid = newItem->pid; item->memBytes = newItem->memBytes; - item->bytesRead = (newItem->bytesRead - oldItem->bytesRead) * 1000u / (uint64_t) elapsed; - item->bytesWritten = (newItem->bytesWritten - oldItem->bytesWritten) * 1000u / (uint64_t) elapsed; + item->bytesRead = (uint64_t) ((double) ((newItem->bytesRead - oldItem->bytesRead) * 1000u) / elapsed + .5); + item->bytesWritten = (uint64_t) ((double) ((newItem->bytesWritten - oldItem->bytesWritten) * 1000u) / elapsed + .5); item->cpuPercent = (double) (newItem->cpuTime - oldItem->cpuTime) / elapsed * 100.0; item->startTime = newItem->startTime; item->threads = newItem->threads;