makeFastBuffer should not segfault but rather throw on non-buffer

This commit is contained in:
Ryan Dahl 2011-05-19 12:13:48 -07:00
parent f4e69e44ff
commit 5e409c2f1a
2 changed files with 9 additions and 0 deletions

View File

@ -679,6 +679,11 @@ Handle<Value> Buffer::ByteLength(const Arguments &args) {
Handle<Value> Buffer::MakeFastBuffer(const Arguments &args) {
HandleScope scope;
if (!Buffer::HasInstance(args[0])) {
return ThrowException(Exception::TypeError(String::New(
"First argument must be a Buffer")));
}
Buffer *buffer = ObjectWrap::Unwrap<Buffer>(args[0]->ToObject());
Local<Object> fast_buffer = args[1]->ToObject();;
uint32_t offset = args[2]->Uint32Value();

View File

@ -520,3 +520,7 @@ assert.equal(0xee, b[0]);
assert.equal(0xad, b[1]);
assert.equal(0xbe, b[2]);
assert.equal(0xef, b[3]);
// This should not segfault the program.
new Buffer('"pong"', 0, 6, 8031, '127.0.0.1')