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

Unified Diff: runtime/vm/flow_graph_optimizer.cc

Issue 24239003: Fix range checks for typed data in native code and the optimizer. (Closed) Base URL: http://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 | « runtime/lib/typed_data.cc ('k') | tests/standalone/typed_data_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/flow_graph_optimizer.cc
===================================================================
--- runtime/vm/flow_graph_optimizer.cc (revision 27650)
+++ runtime/vm/flow_graph_optimizer.cc (working copy)
@@ -2649,9 +2649,27 @@
call->deopt_id());
InsertBefore(call, len_in_bytes, call->env(), Definition::kValue);
- // Check byte_index < len_in_bytes.
+ ConstantInstr* length_adjustment =
+ flow_graph()->GetConstant(Smi::Handle(Smi::New(
+ FlowGraphCompiler::ElementSizeFor(view_cid) - 1)));
+ // adjusted_length = len_in_bytes - (element_size - 1).
+ BinarySmiOpInstr* adjusted_length =
+ new BinarySmiOpInstr(Token::kSUB,
+ new Value(len_in_bytes),
+ new Value(length_adjustment),
+ call->deopt_id());
+ InsertBefore(call, adjusted_length, call->env(), Definition::kValue);
+ // Check adjusted_length > 0.
+ ConstantInstr* zero = flow_graph()->GetConstant(Smi::Handle(Smi::New(0)));
InsertBefore(call,
- new CheckArrayBoundInstr(new Value(len_in_bytes),
+ new CheckArrayBoundInstr(new Value(adjusted_length),
+ new Value(zero),
+ call->deopt_id()),
+ call->env(),
+ Definition::kEffect);
+ // Check 0 <= byte_index < adjusted_length.
+ InsertBefore(call,
+ new CheckArrayBoundInstr(new Value(adjusted_length),
new Value(byte_index),
call->deopt_id()),
call->env(),
« no previous file with comments | « runtime/lib/typed_data.cc ('k') | tests/standalone/typed_data_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698