Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(545)

Unified Diff: runtime/vm/bigint_operations.cc

Issue 207303002: Handle 0 in BigintOperations::ToDecimalCString. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/vm/bigint_operations_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/bigint_operations.cc
===================================================================
--- runtime/vm/bigint_operations.cc (revision 34205)
+++ runtime/vm/bigint_operations.cc (working copy)
@@ -365,7 +365,7 @@
// Approximate the size of the resulting string. We prefer overestimating
// to not allocating enough.
int64_t bit_length = length * kDigitBitSize;
- ASSERT(bit_length > length);
+ ASSERT(bit_length > length || length == 0);
int64_t decimal_length = (bit_length * kLog2Dividend / kLog2Divisor) + 1;
// Add one byte for the trailing \0 character.
int64_t required_size = decimal_length + 1;
@@ -399,8 +399,11 @@
}
ASSERT(part == 0);
}
- // Move the resulting position back until we don't have any zeroes anymore.
- // This is done so that we can remove all leading zeroes.
+ // Add a leading zero, so that we have at least one digit.
+ result[result_pos++] = '0';
+ // Move the resulting position back until we don't have any zeroes anymore
+ // or we reach the first digit. This is done so that we can remove all
+ // redundant leading zeroes.
while (result_pos > 1 && result[result_pos - 1] == '0') {
result_pos--;
}
« no previous file with comments | « no previous file | runtime/vm/bigint_operations_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698