Buffer('') should create a 0-length buffer
authorPeter Griess <pg@std.in>
Wed, 14 Jul 2010 23:07:17 +0000 (18:07 -0500)
committerRyan Dahl <ry@tinyclouds.org>
Thu, 15 Jul 2010 16:54:53 +0000 (09:54 -0700)
src/node_buffer.cc

index 7d7e3554067a5a16aa9ff8d40a8fccca459a7f17..8d35b7e6df1d3e546319de4d992086444ee4ee77 100644 (file)
@@ -352,7 +352,7 @@ Handle<Value> Buffer::Utf8Write(const Arguments &args) {
 
   size_t offset = args[1]->Int32Value();
 
-  if (offset >= buffer->length_) {
+  if (s->Utf8Length() > 0 && offset >= buffer->length_) {
     return ThrowException(Exception::TypeError(String::New(
             "Offset is out of bounds")));
   }
@@ -390,7 +390,7 @@ Handle<Value> Buffer::AsciiWrite(const Arguments &args) {
 
   size_t offset = args[1]->Int32Value();
 
-  if (offset >= buffer->length_) {
+  if (s->Length() > 0 && offset >= buffer->length_) {
     return ThrowException(Exception::TypeError(String::New(
             "Offset is out of bounds")));
   }
@@ -418,7 +418,7 @@ Handle<Value> Buffer::BinaryWrite(const Arguments &args) {
 
   size_t offset = args[1]->Int32Value();
 
-  if (offset >= buffer->length_) {
+  if (s->Length() > 0 && offset >= buffer->length_) {
     return ThrowException(Exception::TypeError(String::New(
             "Offset is out of bounds")));
   }