 Chromium Code Reviews
 Chromium Code Reviews Issue 8509003:
  Limit length of strings copied into a heap snapshot  (Closed) 
  Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
    
  
    Issue 8509003:
  Limit length of strings copied into a heap snapshot  (Closed) 
  Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge| Index: src/objects.cc | 
| diff --git a/src/objects.cc b/src/objects.cc | 
| index e20893615ccc398af8a2cb5ce53ed9a83e4ef313..44ca9e70e150909098b43eb8bf9cbb26bcdac833 100644 | 
| --- a/src/objects.cc | 
| +++ b/src/objects.cc | 
| @@ -5826,11 +5826,9 @@ SmartArrayPointer<char> String::ToCString(AllowNullsFlag allow_nulls, | 
| buffer->Reset(offset, this); | 
| int character_position = offset; | 
| int utf8_bytes = 0; | 
| - while (buffer->has_more()) { | 
| + while (buffer->has_more() && character_position < offset + length) { | 
| uint16_t character = buffer->GetNext(); | 
| - if (character_position < offset + length) { | 
| - utf8_bytes += unibrow::Utf8::Length(character); | 
| - } | 
| + utf8_bytes += unibrow::Utf8::Length(character); | 
| character_position++; | 
| 
mnaganov (inactive)
2011/11/09 11:45:23
This can be moved up into the loop clause.
 | 
| } | 
| @@ -5845,15 +5843,13 @@ SmartArrayPointer<char> String::ToCString(AllowNullsFlag allow_nulls, | 
| buffer->Seek(offset); | 
| character_position = offset; | 
| int utf8_byte_position = 0; | 
| - while (buffer->has_more()) { | 
| + while (buffer->has_more() && character_position < offset + length) { | 
| uint16_t character = buffer->GetNext(); | 
| - if (character_position < offset + length) { | 
| - if (allow_nulls == DISALLOW_NULLS && character == 0) { | 
| - character = ' '; | 
| - } | 
| - utf8_byte_position += | 
| - unibrow::Utf8::Encode(result + utf8_byte_position, character); | 
| + if (allow_nulls == DISALLOW_NULLS && character == 0) { | 
| + character = ' '; | 
| } | 
| + utf8_byte_position += | 
| + unibrow::Utf8::Encode(result + utf8_byte_position, character); | 
| character_position++; | 
| 
mnaganov (inactive)
2011/11/09 11:45:23
Same here.
 | 
| } | 
| result[utf8_byte_position] = 0; |