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

Unified Diff: src/conversions.cc

Issue 2599693002: Fix DoubleToRadixCString wrt Number.MIN_VALUE. (Closed)
Patch Set: Fix DoubleToRadixCString wrt Number.MIN_VALUE. Created 4 years 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 | test/mjsunit/regress/regress-5767.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/conversions.cc
diff --git a/src/conversions.cc b/src/conversions.cc
index 6048b34abf703bbe242572da228e912c1ef52f8d..cf28fb6a10fbed1409c5fe7630458b5084e85873 100644
--- a/src/conversions.cc
+++ b/src/conversions.cc
@@ -436,6 +436,8 @@ char* DoubleToRadixCString(double value, int radix) {
double fraction = value - integer;
// We only compute fractional digits up to the input double's precision.
double delta = 0.5 * (Double(value).NextDouble() - value);
+ delta = std::max(Double(0.0).NextDouble(), delta);
+ DCHECK_GT(delta, 0.0);
if (fraction > delta) {
// Insert decimal point.
buffer[fraction_cursor++] = '.';
@@ -488,6 +490,8 @@ char* DoubleToRadixCString(double value, int radix) {
// Add sign and terminate string.
if (negative) buffer[--integer_cursor] = '-';
buffer[fraction_cursor++] = '\0';
+ DCHECK_LT(fraction_cursor, kBufferSize);
+ DCHECK_LE(0, integer_cursor);
// Allocate new string as return value.
char* result = NewArray<char>(fraction_cursor - integer_cursor);
memcpy(result, buffer + integer_cursor, fraction_cursor - integer_cursor);
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-5767.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698