Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions double-conversion/bignum-dtoa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ static void GenerateCountedDigits(int count, int* decimal_point,
Bignum* numerator, Bignum* denominator,
Vector<char> buffer, int* length) {
DOUBLE_CONVERSION_ASSERT(count >= 0);
if (count == 0) {
// No digits requested. The "last digit" store below would write buffer[-1].
*length = 0;
return;
}
for (int i = 0; i < count - 1; ++i) {
uint16_t digit;
digit = numerator->DivideModuloIntBignum(*denominator);
Expand Down
20 changes: 20 additions & 0 deletions test/cctest/test-bignum-dtoa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,26 @@ TEST(BignumDtoaVariousDoubles) {
}


TEST(BignumDtoaZeroPrecision) {
// Requesting zero precision digits must produce an empty representation
// without storing the "last digit" at buffer[-1]. A sentinel byte sits
// immediately before the output buffer to catch that store.
char container[kBufferSize];
container[0] = '@';
Vector<char> buffer(container + 1, kBufferSize - 1);
int length;
int point;

BignumDtoa(1.0, BIGNUM_DTOA_PRECISION, 0, buffer, &length, &point);
CHECK_EQ(0, length);
CHECK(container[0] == '@');

BignumDtoa(123.456, BIGNUM_DTOA_PRECISION, 0, buffer, &length, &point);
CHECK_EQ(0, length);
CHECK(container[0] == '@');
}


TEST(BignumDtoaShortestVariousFloats) {
char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize);
Expand Down