Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
buffer: use NO_NULL_TERMINATION flag
Browse files Browse the repository at this point in the history
Refs #394.
Fixes #1902.
  • Loading branch information
koichik committed Oct 19, 2011
1 parent b70fed4 commit 6a72e52
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -493,19 +493,12 @@ Handle<Value> Buffer::Utf8Write(const Arguments &args) {
int written = s->WriteUtf8(p,
max_length,
&char_written,
String::HINT_MANY_WRITES_EXPECTED);
(String::HINT_MANY_WRITES_EXPECTED |
String::NO_NULL_TERMINATION));

constructor_template->GetFunction()->Set(chars_written_sym,
Integer::New(char_written));

if (written > 0 && p[written-1] == '\0' && char_written == length) {
uint16_t last_char;
s->Write(&last_char, length - 1, 1, String::NO_OPTIONS);
if (last_char != 0 || written > s->Utf8Length()) {
written--;
}
}

return scope.Close(Integer::New(written));
}

Expand Down Expand Up @@ -538,7 +531,8 @@ Handle<Value> Buffer::Ucs2Write(const Arguments &args) {
int written = s->Write(p,
0,
max_length,
String::HINT_MANY_WRITES_EXPECTED);
(String::HINT_MANY_WRITES_EXPECTED |
String::NO_NULL_TERMINATION));

constructor_template->GetFunction()->Set(chars_written_sym,
Integer::New(written));
Expand Down Expand Up @@ -576,7 +570,8 @@ Handle<Value> Buffer::AsciiWrite(const Arguments &args) {
int written = s->WriteAscii(p,
0,
max_length,
String::HINT_MANY_WRITES_EXPECTED);
(String::HINT_MANY_WRITES_EXPECTED |
String::NO_NULL_TERMINATION));

constructor_template->GetFunction()->Set(chars_written_sym,
Integer::New(written));
Expand Down

0 comments on commit 6a72e52

Please sign in to comment.