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
36 changes: 22 additions & 14 deletions double-conversion/string-to-double.cc
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ double StringToDoubleConverter::StringToIeee(
}

bool leading_zero = false;
bool multiple_leading_zeros = false;
if (*current == '0') {
if (Advance(&current, separator_, 10, end)) {
*processed_characters_count = static_cast<int>(current - input);
Expand Down Expand Up @@ -716,6 +717,7 @@ double StringToDoubleConverter::StringToIeee(

// Ignore leading zeros in the integer part.
while (*current == '0') {
multiple_leading_zeros = true;
if (Advance(&current, separator_, 10, end)) {
*processed_characters_count = static_cast<int>(current - input);
return SignedZero(sign);
Expand Down Expand Up @@ -747,7 +749,9 @@ double StringToDoubleConverter::StringToIeee(
}

if (significant_digits == 0) {
octal = false;
if (!multiple_leading_zeros) {
octal = false;
}
}

if (*current == '.') {
Expand Down Expand Up @@ -882,19 +886,23 @@ double StringToDoubleConverter::StringToIeee(

if (octal) {
double result;
bool result_is_junk;
char* start = buffer;
result = RadixStringToIeee<3>(&start,
buffer + buffer_pos,
sign,
separator_,
false, // Don't parse as hex_float.
allow_trailing_junk,
allow_trailing_spaces,
junk_string_value_,
read_as_double,
&result_is_junk);
DOUBLE_CONVERSION_ASSERT(!result_is_junk);
if (buffer_pos == 0) {
result = SignedZero(sign);
} else {
bool result_is_junk;
char* start = buffer;
result = RadixStringToIeee<3>(&start,
buffer + buffer_pos,
sign,
separator_,
false, // Don't parse as hex_float.
allow_trailing_junk,
allow_trailing_spaces,
junk_string_value_,
read_as_double,
&result_is_junk);
DOUBLE_CONVERSION_ASSERT(!result_is_junk);
}
*processed_characters_count = static_cast<int>(current - input);
return result;
}
Expand Down
22 changes: 22 additions & 0 deletions test/cctest/test-conversions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3596,6 +3596,20 @@ TEST(StringToDoubleOctalString) {
StrToD("01234567e0", flags, Double::NaN(), &processed, &all_used));
CHECK_EQ(0, processed);

CHECK_EQ(Double::NaN(),
StrToD("00.5", flags, Double::NaN(), &processed, &all_used));
CHECK_EQ(0, processed);

CHECK_EQ(Double::NaN(),
StrToD("00e2", flags, Double::NaN(), &processed, &all_used));
CHECK_EQ(0, processed);

CHECK_EQ(0.5, StrToD("0.5", flags, Double::NaN(), &processed, &all_used));
CHECK(all_used);

CHECK_EQ(8.5, StrToD("008.5", flags, Double::NaN(), &processed, &all_used));
CHECK(all_used);


flags = StringToDoubleConverter::ALLOW_OCTALS |
StringToDoubleConverter::ALLOW_TRAILING_JUNK;
Expand Down Expand Up @@ -3753,6 +3767,14 @@ TEST(StringToDoubleOctalString) {
StrToD("01234567e", flags, Double::NaN(), &processed, &all_used));
CHECK_EQ(8, processed);

CHECK_EQ(0.0,
StrToD("00.5", flags, Double::NaN(), &processed, &all_used));
CHECK_EQ(2, processed);

CHECK_EQ(0.0,
StrToD("00e2", flags, Double::NaN(), &processed, &all_used));
CHECK_EQ(2, processed);

flags = StringToDoubleConverter::ALLOW_OCTALS |
StringToDoubleConverter::ALLOW_TRAILING_SPACES |
StringToDoubleConverter::ALLOW_TRAILING_JUNK;
Expand Down
Loading