Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Don't let v8::String::Utf8Write() append '\0' to the output buffer.

v8::String::Utf8Write() appends '\0' if there is room left in
the output buffer. Pass in the exact decoded length obtained
with v8::String::Utf8Length() to make it stop doing that.

Fixes #394.
  • Loading branch information...
commit 22fabd428c9498ccf9c18afd3976fc0e5b40cc1f 1 parent 13a521e
@bnoordhuis authored
Showing with 6 additions and 5 deletions.
  1. +6 −5 src/node_buffer.cc
View
11 src/node_buffer.cc
@@ -475,9 +475,12 @@ Handle<Value> Buffer::Utf8Write(const Arguments &args) {
"Offset is out of bounds")));
}
- size_t max_length = args[2]->IsUndefined() ? buffer->length_ - offset
- : args[2]->Uint32Value();
- max_length = MIN(buffer->length_ - offset, max_length);
+ const size_t utf8len = s->Utf8Length();
+ const size_t len =
+ args[2]->IsUint32()
+ ? MIN(utf8len, args[2]->Uint32Value())
+ : utf8len;
+ const size_t max_length = MIN(len, buffer->length_ - offset);
char* p = buffer->data_ + offset;
@@ -491,8 +494,6 @@ Handle<Value> Buffer::Utf8Write(const Arguments &args) {
constructor_template->GetFunction()->Set(chars_written_sym,
Integer::New(char_written));
- if (written > 0 && p[written-1] == '\0') written--;
-
return scope.Close(Integer::New(written));
}
Please sign in to comment.
Something went wrong with that request. Please try again.