Permalink
Browse files

readCString: return JS `null` when reading a NULL pointer

Test case included, that was seg faulting before
  • Loading branch information...
1 parent 995e957 commit de81ae50e4c2926de43c569217d29e35a4419ec9 @TooTallNate committed May 31, 2012
Showing with 9 additions and 1 deletion.
  1. +5 −1 src/binding.cc
  2. +4 −0 test/string.js
View
@@ -433,7 +433,11 @@ Handle<Value> ReadCString(const Arguments& args) {
int64_t offset = args[1]->IntegerValue();
char *ptr = Buffer::Data(buf.As<Object>()) + offset;
- return scope.Close(String::New(ptr));
+ Handle<Value> rtn = Null();
+ if (ptr != NULL) {
+ rtn = String::New(ptr);
+ }
+ return scope.Close(rtn);
}
/*
View
@@ -16,6 +16,10 @@ describe('C string', function () {
assert.strictEqual('hello', buf.readCString(0))
})
+ it('should return `null` when reading a NULL pointer', function () {
+ assert.strictEqual(null, ref.NULL.readCString())
+ })
+
})
describe('writeCString()', function () {

0 comments on commit de81ae5

Please sign in to comment.