When you use KFormat::formatDuration with a very large duration, and you pass an option (ex. ShowMilliseconds), the returned value is different than if it was without the option. Python example (same issue in C++ and QMl): from PyKF5 import KCoreAddons INT = 9999999999 mformat = KCoreAddons.KFormat() print("KFormat.ShowMilliseconds: {}".format(mformat.formatDuration(INT, KCoreAddons.KFormat.ShowMilliseconds))) print("No options: {}".format(mformat.formatDuration(INT))) >> KFormat.ShowMilliseconds: 2777:46:39.999 >> No options: 391:41:05
Currently uses qRound, which returns int, but either should use qRound64 (and double instead of qreal), or just use int arithmetic for rounding, e.g. ((x + 50) / 100) * 100 will round to multiple of 100. https://cgit.kde.org/kcoreaddons.git/tree/src/lib/util/kformatprivate.cpp#n332
https://phabricator.kde.org/D14565
Git commit ea2779611800e72b516f400abf18aa8ef4abfaec by Sune Vuorela. Committed on 03/08/2018 at 16:01. Pushed by sune into branch 'master'. Fix overflow in rounding code Summary: qRound works with int. Test Plan: add unit tests Reviewers: cfeck, safaalfulaij Reviewed By: cfeck, safaalfulaij Subscribers: kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D14565 M +11 -0 autotests/kformattest.cpp M +2 -2 src/lib/util/kformatprivate.cpp https://commits.kde.org/kcoreaddons/ea2779611800e72b516f400abf18aa8ef4abfaec