Permalink
Browse files

buffer: do not call v8::AsciiWrite for zero-buffer

buffer.data_ is NULL in this case and, for some reason, v8 3.14 on
smartos doesn't handle this well (simple/test-buffer is crashing).
  • Loading branch information...
indutny committed Feb 26, 2013
1 parent aa98539 commit f9c0b525c944dc7e7b53cfc7d4c1e9622503036a
Showing with 5 additions and 0 deletions.
  1. +5 −0 src/node_buffer.cc
View
@@ -629,6 +629,11 @@ Handle<Value> Buffer::AsciiWrite(const Arguments &args) {
return ThrowTypeError("Offset is out of bounds");
}
+ // Avoid calling WriteAscii on empty buffer, data_ is NULL in such case and
+ // old v8 versions (like 3.14) doesn't handle this well.
+ if (length == 0)
+ return scope.Close(Integer::New(0, node_isolate));
+
size_t max_length = args[2]->IsUndefined() ? buffer->length_ - offset
: args[2]->Uint32Value();
max_length = MIN(length, MIN(buffer->length_ - offset, max_length));

0 comments on commit f9c0b52

Please sign in to comment.