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

Side by Side Diff: runtime/lib/double_patch.dart

Issue 623073002: Fix wrong limit on list index in double.parse. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/corelib/double_parse_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 // Dart core library. 4 // Dart core library.
5 5
6 // VM implementation of double. 6 // VM implementation of double.
7 7
8 patch class double { 8 patch class double {
9 9
10 static double _nativeParse(String str, 10 static double _nativeParse(String str,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 10000000000000000000.0, 105 10000000000000000000.0,
106 100000000000000000000.0, /* 20 */ 106 100000000000000000000.0, /* 20 */
107 1000000000000000000000.0, 107 1000000000000000000000.0,
108 10000000000000000000000.0, 108 10000000000000000000000.0,
109 ]; 109 ];
110 if (exponent < 0) { 110 if (exponent < 0) {
111 int negExponent = -exponent; 111 int negExponent = -exponent;
112 if (negExponent >= P10.length) return null; 112 if (negExponent >= P10.length) return null;
113 return sign * (doubleValue / P10[negExponent]); 113 return sign * (doubleValue / P10[negExponent]);
114 } 114 }
115 if (exponent > P10.length) return null; 115 if (exponent >= P10.length) return null;
116 return sign * (doubleValue * P10[exponent]); 116 return sign * (doubleValue * P10[exponent]);
117 } 117 }
118 118
119 static double _parse(var str) { 119 static double _parse(var str) {
120 int len = str.length; 120 int len = str.length;
121 int start = str._firstNonWhitespace(); 121 int start = str._firstNonWhitespace();
122 if (start == len) return null; // All whitespace. 122 if (start == len) return null; // All whitespace.
123 int end = str._lastNonWhitespace() + 1; 123 int end = str._lastNonWhitespace() + 1;
124 assert(start < end); 124 assert(start < end);
125 var result = _tryParseDouble(str, start, end); 125 var result = _tryParseDouble(str, start, end);
126 if (result != null) return result; 126 if (result != null) return result;
127 return _nativeParse(str, start, end); 127 return _nativeParse(str, start, end);
128 } 128 }
129 129
130 /* patch */ static double parse(String str, 130 /* patch */ static double parse(String str,
131 [double onError(String str)]) { 131 [double onError(String str)]) {
132 var result = _parse(str); 132 var result = _parse(str);
133 if (result == null) { 133 if (result == null) {
134 if (onError == null) throw new FormatException("Invalid double", str); 134 if (onError == null) throw new FormatException("Invalid double", str);
135 return onError(str); 135 return onError(str);
136 } 136 }
137 return result; 137 return result;
138 } 138 }
139 } 139 }
OLDNEW
« no previous file with comments | « no previous file | tests/corelib/double_parse_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698