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

Unified Diff: runtime/vm/object.cc

Issue 25344002: Fix crashing bug due to the fact that external one byte strings cannot be escaped (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 | « runtime/vm/object.h ('k') | runtime/vm/object_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index f25f106c3a0ca8e11e0d3a6daef9e46e0c15172f..df62a758552e301c633970bb53914b00696a70b0 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -13244,8 +13244,18 @@ RawString* String::EscapeSpecialCharacters(const String& str) {
if (str.IsOneByteString()) {
return OneByteString::EscapeSpecialCharacters(str);
}
- ASSERT(str.IsTwoByteString());
- return TwoByteString::EscapeSpecialCharacters(str);
+ if (str.IsTwoByteString()) {
+ return TwoByteString::EscapeSpecialCharacters(str);
+ }
+ if (str.IsExternalOneByteString()) {
+ return ExternalOneByteString::EscapeSpecialCharacters(str);
+ }
+ ASSERT(str.IsExternalTwoByteString());
+ // If EscapeSpecialCharacters is frequently called on external two byte
+ // strings, we should implement it directly on ExternalTwoByteString rather
+ // than first converting to a TwoByteString.
+ return TwoByteString::EscapeSpecialCharacters(
+ String::Handle(TwoByteString::New(str, Heap::kNew)));
}
@@ -13673,6 +13683,35 @@ RawOneByteString* OneByteString::EscapeSpecialCharacters(const String& str) {
return OneByteString::null();
}
+RawOneByteString* ExternalOneByteString::EscapeSpecialCharacters(
+ const String& str) {
+ intptr_t len = str.Length();
+ if (len > 0) {
+ intptr_t num_escapes = 0;
+ intptr_t index = 0;
hausner 2013/09/30 22:54:37 declare index just before the loop below where it'
Jacob 2013/09/30 23:53:28 Fixed that here and in the code this method was co
+ for (intptr_t i = 0; i < len; i++) {
+ if (IsSpecialCharacter(*CharAddr(str, i))) {
+ num_escapes += 1;
+ }
+ }
+ const String& dststr = String::Handle(
+ OneByteString::New(len + num_escapes, Heap::kNew));
+ for (intptr_t i = 0; i < len; i++) {
+ if (IsSpecialCharacter(*CharAddr(str, i))) {
+ *(OneByteString::CharAddr(dststr, index)) = '\\';
+ *(OneByteString::CharAddr(dststr, index + 1)) =
+ SpecialCharacter(*CharAddr(str, i));
+ index += 2;
+ } else {
+ *(OneByteString::CharAddr(dststr, index)) = *CharAddr(str, i);
+ index += 1;
+ }
+ }
+ return OneByteString::raw(dststr);
+ }
+ return OneByteString::null();
hausner 2013/09/30 22:54:37 It it correct to return null when the input string
Jacob 2013/09/30 23:53:28 That is what the existing code did but I agree it
+}
+
RawOneByteString* OneByteString::New(intptr_t len,
Heap::Space space) {
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698