Skip to content

Commit d83d2ba

Browse files
committed
Trim all zeros from input
If the buffer only contains zeros, return 0.
1 parent c59ecc8 commit d83d2ba

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

include/rapidjson/internal/strtod.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,17 +242,21 @@ inline double StrtodFullPrecision(double d, int p, const char* decimals, size_t
242242
RAPIDJSON_ASSERT(dExp <= INT_MAX - dLen);
243243

244244
// Trim leading zeros
245-
while (*decimals == '0' && dLen > 1) {
245+
while (dLen > 0 && *decimals == '0') {
246246
dLen--;
247247
decimals++;
248248
}
249249

250250
// Trim trailing zeros
251-
while (decimals[dLen - 1] == '0' && dLen > 1) {
251+
while (dLen > 0 && decimals[dLen - 1] == '0') {
252252
dLen--;
253253
dExp++;
254254
}
255255

256+
if (dLen == 0) { // Buffer only contains zeros.
257+
return 0.0;
258+
}
259+
256260
// Trim right-most digits
257261
const int kMaxDecimalDigit = 780;
258262
if (dLen > kMaxDecimalDigit) {

0 commit comments

Comments
 (0)