Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ensure `readPointer()` returns JS `null` when reading from the NULL p…

…ointer

Test case included. Prevents segmentation fault, which is always worse.
  • Loading branch information...
commit 2934c8c8e03d2cca2ef0ae667e24006caf2c671a 1 parent ac97e81
@TooTallNate authored
Showing with 11 additions and 4 deletions.
  1. +7 −4 src/binding.cc
  2. +4 −0 test/pointer.js
View
11 src/binding.cc
@@ -218,12 +218,15 @@ Handle<Value> ReadPointer(const Arguments& args) {
int64_t offset = args[1]->IntegerValue();
char *ptr = Buffer::Data(buf.As<Object>()) + offset;
-
size_t size = args[2]->Uint32Value();
- char *val = *reinterpret_cast<char **>(ptr);
- Buffer *rtn = Buffer::New(val, size, read_pointer_cb, NULL);
- return scope.Close(rtn->handle_);
+ Handle<Value> rtn = Null();
+ if (ptr != NULL) {
+ char *val = *reinterpret_cast<char **>(ptr);
+ Buffer *rtn_buf = Buffer::New(val, size, read_pointer_cb, NULL);
+ rtn = rtn_buf->handle_;
+ }
+ return scope.Close(rtn);
}
/*
View
4 test/pointer.js
@@ -45,4 +45,8 @@ describe('pointer', function () {
assert(child_gc, '"child" has not been garbage collected')
})
+ it('should return JS `null` when reading a NULL pointer', function () {
+ assert.strictEqual(null, ref.NULL.readPointer())
+ })
+
})
Please sign in to comment.
Something went wrong with that request. Please try again.