From e95a017e3358c6891aeeb343625604e8bf8c9b3a Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 17 Jun 2015 08:03:51 +0800 Subject: [PATCH] Fix potential out-of-bound access of units[i] --- src/core/utils/misc.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/utils/misc.cpp b/src/core/utils/misc.cpp index 7860f774c..ae4840ae2 100644 --- a/src/core/utils/misc.cpp +++ b/src/core/utils/misc.cpp @@ -258,8 +258,10 @@ QString Utils::Misc::friendlyUnit(qreal val, bool is_speed) if (val < 0) return QCoreApplication::translate("misc", "Unknown", "Unknown (size)"); int i = 0; - while(val >= 1024. && i++<6) + while(val >= 1024. && i < 4) { val /= 1024.; + ++i; + } QString ret; if (i == 0) ret = QString::number((long)val) + " " + QCoreApplication::translate("misc", units[0].source, units[0].comment);