From d4b7afefef2034920f1e8027af2ce292b7510592 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Thu, 7 Oct 2021 13:55:59 +0200 Subject: NiceByteRateToBuffer could cause a divide-by-zero in some cases - fixed --- zencore/string.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'zencore/string.cpp') diff --git a/zencore/string.cpp b/zencore/string.cpp index 6dcdc9542..49824a910 100644 --- a/zencore/string.cpp +++ b/zencore/string.cpp @@ -341,7 +341,17 @@ NiceBytesToBuffer(uint64_t Num, std::span Buffer) size_t NiceByteRateToBuffer(uint64_t Num, uint64_t ElapsedMs, std::span Buffer) { - size_t n = NiceNumGeneral(Num * 1000 / ElapsedMs, Buffer, kNicenumBytes); + size_t n = 0; + + if (ElapsedMs) + { + n = NiceNumGeneral(Num * 1000 / ElapsedMs, Buffer, kNicenumBytes); + } + else + { + Buffer[n++] = '0'; + Buffer[n++] = 'B'; + } Buffer[n++] = '/'; Buffer[n++] = 's'; -- cgit v1.2.3