Commit 928caf92 authored by Milo Yip's avatar Milo Yip

Fix gcc strict-overflow warning

Fix #566 #568
parent 6c927047
......@@ -148,7 +148,7 @@ inline char* WriteExponent(int K, char* buffer) {
inline char* Prettify(char* buffer, int length, int k, int maxDecimalPlaces) {
const int kk = length + k; // 10^(kk-1) <= v < 10^kk
if (length <= kk && kk <= 21) {
if (0 <= k && kk <= 21) {
// 1234e7 -> 12340000000
for (int i = length; i < kk; i++)
buffer[i] = '0';
......@@ -160,7 +160,7 @@ inline char* Prettify(char* buffer, int length, int k, int maxDecimalPlaces) {
// 1234e-2 -> 12.34
std::memmove(&buffer[kk + 1], &buffer[kk], static_cast<size_t>(length - kk));
buffer[kk] = '.';
if (length > kk + maxDecimalPlaces) {
if (0 > k + maxDecimalPlaces) {
// When maxDecimalPlaces = 2, 1.2345 -> 1.23, 1.102 -> 1.1
// Remove extra trailing zeros (at least one) after truncation.
for (int i = kk + maxDecimalPlaces; i > kk + 1; i--)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment