@@ -1525,7 +1525,7 @@ static void SetDetachKey(const FunctionCallbackInfo<Value>& args) {
15251525namespace {
15261526
15271527bool ReadNonNegativeInteger (Local<Value> value, uint64_t * result) {
1528- constexpr double kMaxSafeInteger = 9007199254740991.0 ;
1528+ constexpr double kMaxSafeInteger = static_cast < double >(( 1LL << 53 ) - 1 ) ;
15291529 double number = value.As <Number>()->Value ();
15301530 if (number < 0 || number > kMaxSafeInteger ) {
15311531 return false ;
@@ -1582,22 +1582,14 @@ void CopyArrayBuffer(const FunctionCallbackInfo<Value>& args) {
15821582 CHECK (ReadNonNegativeInteger (args[3 ], &source_offset));
15831583 CHECK (ReadNonNegativeInteger (args[4 ], &bytes_to_copy));
15841584
1585- const uint64_t destination_offset_u = destination_offset;
1586- const uint64_t source_offset_u = source_offset;
1587- const uint64_t bytes_to_copy_u = bytes_to_copy;
1588- const uint64_t destination_byte_length_u = destination_byte_length;
1589- const uint64_t source_byte_length_u = source_byte_length;
1590- CHECK_LE (destination_offset_u, destination_byte_length_u);
1591- CHECK_LE (source_offset_u, source_byte_length_u);
1592- CHECK_LE (bytes_to_copy_u, destination_byte_length_u - destination_offset_u);
1593- CHECK_LE (bytes_to_copy_u, source_byte_length_u - source_offset_u);
1594-
1595- const size_t destination_offset_s = static_cast <size_t >(destination_offset_u);
1596- const size_t source_offset_s = static_cast <size_t >(source_offset_u);
1597- const size_t bytes_to_copy_s = static_cast <size_t >(bytes_to_copy_u);
1598- uint8_t * dest = static_cast <uint8_t *>(destination) + destination_offset_s;
1599- uint8_t * src = static_cast <uint8_t *>(source) + source_offset_s;
1600- memcpy (dest, src, bytes_to_copy_s);
1585+ CHECK_LE (destination_offset, static_cast <uint64_t >(destination_byte_length));
1586+ CHECK_LE (source_offset, static_cast <uint64_t >(source_byte_length));
1587+ CHECK_LE (bytes_to_copy, static_cast <uint64_t >(destination_byte_length) - destination_offset);
1588+ CHECK_LE (bytes_to_copy, static_cast <uint64_t >(source_byte_length) - source_offset);
1589+
1590+ uint8_t * dest = static_cast <uint8_t *>(destination) + static_cast <size_t >(destination_offset);
1591+ uint8_t * src = static_cast <uint8_t *>(source) + static_cast <size_t >(source_offset);
1592+ memcpy (dest, src, static_cast <size_t >(bytes_to_copy));
16011593}
16021594
16031595// Converts a number parameter to size_t suitable for ArrayBuffer sizes
0 commit comments