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

Unified Diff: src/conversions-inl.h

Issue 2548243004: Return false in TryNumberToSize if there is a cast error (Closed)
Patch Set: Return false in TryNumberToSize if there is a cast error 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
Index: src/conversions-inl.h
diff --git a/src/conversions-inl.h b/src/conversions-inl.h
index 427a67d1097b717facd06be847bdc85e11a5e53c..24e1724c86dbea7f80b0bfd23be15be82a9f4b15 100644
--- a/src/conversions-inl.h
+++ b/src/conversions-inl.h
@@ -156,6 +156,11 @@ bool TryNumberToSize(Object* number, size_t* result) {
double value = HeapNumber::cast(number)->value();
if (value >= 0 && value <= std::numeric_limits<size_t>::max()) {
ahaas 2016/12/07 16:20:38 The problem here is that if you compare a double w
qiuyi.zqy 2016/12/07 18:13:36 Done.
*result = static_cast<size_t>(value);
+ // Cast error. Could happen when value is slightly larger than
+ // the limit of size_t but has a floating number precision loss.
+ if (value > 0 && *result == 0) {
+ return false;
+ }
return true;
} else {
return false;
« no previous file with comments | « AUTHORS ('k') | test/cctest/test-conversions.cc » ('j') | test/cctest/test-conversions.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698