From af7bf8a97a779a69c9835f6f8a6c7894186d3993 Mon Sep 17 00:00:00 2001 From: Carsten Larsen Date: Sat, 4 Feb 2017 12:52:26 +0100 Subject: [PATCH] Fixed truncation bug --- app/lib/charbuf.cpp | 18 ++++++++++++++++++ app/lib/charbuf.h | 1 + app/lib/ntext.cpp | 13 ++++++++----- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/app/lib/charbuf.cpp b/app/lib/charbuf.cpp index 90225090..b0207450 100644 --- a/app/lib/charbuf.cpp +++ b/app/lib/charbuf.cpp @@ -165,6 +165,24 @@ bool CharBuffer::Is(const char* string) return StrIsEqual(GetString(), string); } +bool CharBuffer::Contains(const char c) +{ + char* i = buf; + + if (i == NOMEM || buf == ptr) + return false; + + do + { + if (*i == c) + return true; + + i++; + } while (i != ptr); + + return false; +} + void CharBuffer::Empty() { if (buf == NOMEM) { diff --git a/app/lib/charbuf.h b/app/lib/charbuf.h index ce531ef8..c24b1981 100644 --- a/app/lib/charbuf.h +++ b/app/lib/charbuf.h @@ -59,6 +59,7 @@ public: * @brief Compare content of CharBuffer with string) */ bool Is(const char *string); + bool Contains(const char c); void Copy(CharBuffer *buf); void Append(const char *source); diff --git a/app/lib/ntext.cpp b/app/lib/ntext.cpp index 4d0789c4..9b88d771 100644 --- a/app/lib/ntext.cpp +++ b/app/lib/ntext.cpp @@ -444,11 +444,14 @@ const char* DecimalSystem::GetRealText(double value) PrintFloat64(out, size, roundedvalue, format, formatdigits, fractionpoint); buf->EnsureGrowth(size); buf->Append(out); - while (buf->RemoveTrailing('0')) - ; - buf->RemoveTrailing(fractionpoint); - delete[] out; + if (fractionpoint != '\0' && buf->Contains(fractionpoint)) + { + while (buf->RemoveTrailing('0')) + ; + buf->RemoveTrailing(fractionpoint); + } + + delete[] out; return buf->GetString(); } -