Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bufferpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ function BufferPack() {
bBE = (fmt.charAt(0) != '<');

p = p?p:0;
var al = a.length;
var re = new RegExp(this._sPattern, 'g');
var m;
var n;
Expand All @@ -186,6 +187,8 @@ function BufferPack() {
n = 0; // Need to deal with empty null term strings
while(a[p + n] !== 0) {
n++;
if (p + n >= al) // Don't read past the end of the buffer
return undefined;
}
n++; // Add one for null byte
}
Expand Down
9 changes: 9 additions & 0 deletions test/cstring.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,14 @@ describe('C String', function() {
unpacked.forth.should.equal('asdf');
});
});
describe('strings without null terminators', function() {
var values = [0x3c];
var packed = bufferpack.pack('b', values);

it('should return undefined', function() {
var unpacked = bufferpack.unpack('S', packed);
(unpacked === undefined).should.be.true;
});
});
});
});