Trim all zeros from input

If the buffer only contains zeros, return 0.
This commit is contained in:
abolz 2018-06-15 10:46:45 +02:00
parent c59ecc857d
commit d83d2ba260

View File

@ -242,17 +242,21 @@ inline double StrtodFullPrecision(double d, int p, const char* decimals, size_t
RAPIDJSON_ASSERT(dExp <= INT_MAX - dLen);
// Trim leading zeros
while (*decimals == '0' && dLen > 1) {
while (dLen > 0 && *decimals == '0') {
dLen--;
decimals++;
}
// Trim trailing zeros
while (decimals[dLen - 1] == '0' && dLen > 1) {
while (dLen > 0 && decimals[dLen - 1] == '0') {
dLen--;
dExp++;
}
if (dLen == 0) { // Buffer only contains zeros.
return 0.0;
}
// Trim right-most digits
const int kMaxDecimalDigit = 780;
if (dLen > kMaxDecimalDigit) {