Permalink
Browse files

make passing `ref.NULL` to allocCString() work as expected

  • Loading branch information...
1 parent d80b147 commit 0eba2cace15ec9375d1b41969b18386936074561 @TooTallNate committed Sep 28, 2012
Showing with 7 additions and 1 deletion.
  1. +1 −1 lib/ref.js
  2. +6 −0 test/string.js
View
@@ -534,7 +534,7 @@ exports.alloc = function alloc (_type, value) {
*/
exports.allocCString = function allocCString (string, encoding) {
- if (string === null || typeof string === 'undefined') {
+ if (null == string || (Buffer.isBuffer(string) && exports.isNull(string))) {
return exports.NULL
}
var size = Buffer.byteLength(string, encoding) + 1
View
@@ -57,6 +57,12 @@ describe('C string', function () {
assert.strictEqual(0, buf.address())
})
+ it('should return the NULL pointer for a NULL pointer Buffer', function () {
+ var buf = ref.allocCString(ref.NULL)
+ assert(buf.isNull())
+ assert.strictEqual(0, buf.address())
+ })
+
})
describe('CString', function () {

0 comments on commit 0eba2ca

Please sign in to comment.