From 1baefdd0f2585f13444b2352b1bed51b2691db9e Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Thu, 15 May 2014 23:31:32 -0700 Subject: [PATCH] Properly handle zero --- Sources/Plasma/CoreLib/plFormat.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sources/Plasma/CoreLib/plFormat.cpp b/Sources/Plasma/CoreLib/plFormat.cpp index 2b2ae1e1..2f6ddb3e 100644 --- a/Sources/Plasma/CoreLib/plFormat.cpp +++ b/Sources/Plasma/CoreLib/plFormat.cpp @@ -190,6 +190,11 @@ namespace plFormat_Private template void _IFormatNumeric_Impl(char *output_end, _IType value, int radix, bool upperCase = false) { + if (value == 0) { + *(output_end - 1) = '0'; + return; + } + while (value) { int digit = (value % radix); @@ -218,6 +223,9 @@ static plStringBuffer _formatNumeric(const plFormat_Private::FormatSpec &f temp /= radix; } + if (max == 0) + max = 1; + plStringBuffer buffer; if (format.fPrecisionLeft > max) { char *output = buffer.CreateWritableBuffer(format.fPrecisionLeft); @@ -252,6 +260,9 @@ static plStringBuffer _formatDecimal(const plFormat_Private::FormatSpec &f temp /= 10; } + if (max == 0) + max = 1; + if (value < 0 || format.fDigitClass == plFormat_Private::kDigitDecAlwaysSigned) ++max;