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

Unified Diff: runtime/lib/typed_data.dart

Issue 23686003: Add alignment checks to typed_data views (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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 | tests/co19/co19-runtime.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/typed_data.dart
diff --git a/runtime/lib/typed_data.dart b/runtime/lib/typed_data.dart
index 0a8b0ef8811c787fdc428633e9bedc46aae41e89..1007c4909de51f4c74065eddc218d1db9e53b1ea 100644
--- a/runtime/lib/typed_data.dart
+++ b/runtime/lib/typed_data.dart
@@ -2325,6 +2325,7 @@ class _Int16ArrayView extends _TypedListView implements Int16List {
_rangeCheck(buffer.lengthInBytes,
offsetInBytes,
length * Int16List.BYTES_PER_ELEMENT);
+ _offsetAlignmentCheck(_offsetInBytes, Int16List.BYTES_PER_ELEMENT);
}
@@ -2376,6 +2377,7 @@ class _Uint16ArrayView extends _TypedListView implements Uint16List {
_rangeCheck(buffer.lengthInBytes,
offsetInBytes,
length * Uint16List.BYTES_PER_ELEMENT);
+ _offsetAlignmentCheck(_offsetInBytes, Uint16List.BYTES_PER_ELEMENT);
}
@@ -2427,6 +2429,7 @@ class _Int32ArrayView extends _TypedListView implements Int32List {
_rangeCheck(buffer.lengthInBytes,
offsetInBytes,
length * Int32List.BYTES_PER_ELEMENT);
+ _offsetAlignmentCheck(_offsetInBytes, Int32List.BYTES_PER_ELEMENT);
}
@@ -2478,6 +2481,7 @@ class _Uint32ArrayView extends _TypedListView implements Uint32List {
_rangeCheck(buffer.lengthInBytes,
offsetInBytes,
length * Uint32List.BYTES_PER_ELEMENT);
+ _offsetAlignmentCheck(_offsetInBytes, Uint32List.BYTES_PER_ELEMENT);
}
@@ -2529,6 +2533,7 @@ class _Int64ArrayView extends _TypedListView implements Int64List {
_rangeCheck(buffer.lengthInBytes,
offsetInBytes,
length * Int64List.BYTES_PER_ELEMENT);
+ _offsetAlignmentCheck(_offsetInBytes, Int64List.BYTES_PER_ELEMENT);
}
@@ -2580,6 +2585,7 @@ class _Uint64ArrayView extends _TypedListView implements Uint64List {
_rangeCheck(buffer.lengthInBytes,
offsetInBytes,
length * Uint64List.BYTES_PER_ELEMENT);
+ _offsetAlignmentCheck(_offsetInBytes, Uint64List.BYTES_PER_ELEMENT);
}
@@ -2631,6 +2637,7 @@ class _Float32ArrayView extends _TypedListView implements Float32List {
_rangeCheck(buffer.lengthInBytes,
offsetInBytes,
length * Float32List.BYTES_PER_ELEMENT);
+ _offsetAlignmentCheck(_offsetInBytes, Float32List.BYTES_PER_ELEMENT);
}
@@ -2682,6 +2689,7 @@ class _Float64ArrayView extends _TypedListView implements Float64List {
_rangeCheck(buffer.lengthInBytes,
offsetInBytes,
length * Float64List.BYTES_PER_ELEMENT);
+ _offsetAlignmentCheck(_offsetInBytes, Float64List.BYTES_PER_ELEMENT);
}
@@ -2733,6 +2741,7 @@ class _Float32x4ArrayView extends _TypedListView implements Float32x4List {
_rangeCheck(buffer.lengthInBytes,
offsetInBytes,
length * Float32x4List.BYTES_PER_ELEMENT);
+ _offsetAlignmentCheck(_offsetInBytes, Float32x4List.BYTES_PER_ELEMENT);
}
@@ -3125,6 +3134,14 @@ void _rangeCheck(int listLength, int start, int length) {
}
+void _offsetAlignmentCheck(int offset, int alignment) {
+ if ((offset % alignment) != 0) {
+ throw new RangeError('Offset ($offset) must be a multiple of '
+ 'BYTES_PER_ELEMENT ($alignment)');
+ }
+}
+
+
int _defaultIfNull(object, value) {
if (object == null) {
return value;
« no previous file with comments | « no previous file | tests/co19/co19-runtime.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698