Status: New
Owner: ----

New issue 975 by alex.fritze: String::Write doesn't work correctly with start!=0
http://code.google.com/p/v8/issues/detail?id=975

The String::Write(.) logic is broken when called with 'start' set to something other than 0. The fault is in how 'end' gets calculated from 'length'. 'end' is an index into the string, 'length' is not. Here's a patch:


diff --git a/deps/v8/src/api.cc b/deps/v8/src/api.cc
index 0ec8cf1..fb6ddc4 100644
--- a/deps/v8/src/api.cc
+++ b/deps/v8/src/api.cc
@@ -3119,12 +3119,12 @@ int String::Write(uint16_t* buffer,
     // using StringInputBuffer or Get(i) to access the characters.
     str->TryFlatten();
   }
-  int end = length;
+  int end = length+start;
   if ( (length == -1) || (length > str->length() - start) )
-    end = str->length() - start;
+    end = str->length();
   if (end < 0) return 0;
   i::String::WriteToFlat(*str, buffer, start, end);
-  if (length == -1 || end < length)
+  if (length == -1 || end-start < length)
     buffer[end] = '\0';
   return end;
 }


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to