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

Commit 6a72e52

Browse files
committed
buffer: use NO_NULL_TERMINATION flag
Refs #394. Fixes #1902.
1 parent b70fed4 commit 6a72e52

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/node_buffer.cc

+6-11
Original file line numberDiff line numberDiff line change
@@ -493,19 +493,12 @@ Handle<Value> Buffer::Utf8Write(const Arguments &args) {
493493
int written = s->WriteUtf8(p,
494494
max_length,
495495
&char_written,
496-
String::HINT_MANY_WRITES_EXPECTED);
496+
(String::HINT_MANY_WRITES_EXPECTED |
497+
String::NO_NULL_TERMINATION));
497498

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

501-
if (written > 0 && p[written-1] == '\0' && char_written == length) {
502-
uint16_t last_char;
503-
s->Write(&last_char, length - 1, 1, String::NO_OPTIONS);
504-
if (last_char != 0 || written > s->Utf8Length()) {
505-
written--;
506-
}
507-
}
508-
509502
return scope.Close(Integer::New(written));
510503
}
511504

@@ -538,7 +531,8 @@ Handle<Value> Buffer::Ucs2Write(const Arguments &args) {
538531
int written = s->Write(p,
539532
0,
540533
max_length,
541-
String::HINT_MANY_WRITES_EXPECTED);
534+
(String::HINT_MANY_WRITES_EXPECTED |
535+
String::NO_NULL_TERMINATION));
542536

543537
constructor_template->GetFunction()->Set(chars_written_sym,
544538
Integer::New(written));
@@ -576,7 +570,8 @@ Handle<Value> Buffer::AsciiWrite(const Arguments &args) {
576570
int written = s->WriteAscii(p,
577571
0,
578572
max_length,
579-
String::HINT_MANY_WRITES_EXPECTED);
573+
(String::HINT_MANY_WRITES_EXPECTED |
574+
String::NO_NULL_TERMINATION));
580575

581576
constructor_template->GetFunction()->Set(chars_written_sym,
582577
Integer::New(written));

0 commit comments

Comments
 (0)