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

Unified Diff: runtime/lib/typed_data.cc

Issue 15743017: Adds a flag to the standalone vm to throw an exception on 53-bit integer overflow. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 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
Index: runtime/lib/typed_data.cc
===================================================================
--- runtime/lib/typed_data.cc (revision 23032)
+++ runtime/lib/typed_data.cc (working copy)
@@ -13,6 +13,8 @@
namespace dart {
+DECLARE_FLAG(bool, throw_on_53bit_overflow);
+
// TypedData.
// Checks to see if offset_in_bytes is in the range.
@@ -261,6 +263,11 @@
} else { \
result = Integer::New(value); \
} \
+ if (FLAG_throw_on_53bit_overflow && !result.FitsIn53Bits()) { \
+ const Array& exc_args = Array::Handle(Array::New(1)); \
+ exc_args.SetAt(0, Object::Handle(String::New("TypedData_getter"))); \
+ Exceptions::ThrowByType(Exceptions::kFiftyThreeBitOverflowError, exc_args);\
+ } \
return result.raw(); \
} \
@@ -384,7 +391,13 @@
} else {
value = Utils::HostToBigEndian64(value);
}
- return Integer::New(value);
+ const Integer& i = Integer::Handle(Integer::New(value));
+ if (FLAG_throw_on_53bit_overflow && !i.FitsIn53Bits()) {
+ const Array& exc_args = Array::Handle(Array::New(1));
+ exc_args.SetAt(0, Object::Handle(String::New("ByteData_ToEndianInt64")));
+ Exceptions::ThrowByType(Exceptions::kFiftyThreeBitOverflowError, exc_args);
+ }
+ return i.AsValidInteger();
siva 2013/05/23 01:28:22 Ditto comment about the AsValidInteger.
zra 2013/05/23 15:59:07 Done.
}
@@ -408,7 +421,13 @@
if (value > static_cast<uint64_t>(Mint::kMaxValue)) {
siva 2013/05/23 01:28:22 What about throwing an exception here?
zra 2013/05/23 15:59:07 Yes, I've added a throw here, too.
return BigintOperations::NewFromUint64(value);
}
- return Integer::New(value);
+ const Integer& i = Integer::Handle(Integer::New(value));
+ if (FLAG_throw_on_53bit_overflow && !i.FitsIn53Bits()) {
+ const Array& exc_args = Array::Handle(Array::New(1));
+ exc_args.SetAt(0, Object::Handle(String::New("ByteData_ToEndianUint64")));
+ Exceptions::ThrowByType(Exceptions::kFiftyThreeBitOverflowError, exc_args);
+ }
+ return i.AsValidInteger();
siva 2013/05/23 01:28:22 Ditto comment about AsValidInteger
zra 2013/05/23 15:59:07 Done.
}
« runtime/lib/integers.cc ('K') | « runtime/lib/integers.cc ('k') | runtime/vm/exceptions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698