Skip to content

Commit

Permalink
feat: avoid negative sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
dryajov authored and jacobheun committed Feb 7, 2019
1 parent 99a0c46 commit 55d096e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/coder.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ exports.decode = () => {
let pos = 0
const read = (msg, data, length) => {
let left = length - msg.length
if (left < 0) { left = 0 }
if (msg.length > 0) {
const buff = msg.slice(0, length - left)
pos += buff.copy(data, pos)
Expand Down
2 changes: 1 addition & 1 deletion test/coder.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('coder', () => {
coder.encode(),
pull.collect((err, data) => {
expect(err).to.not.exist()
expect(data[0]).to.be.eql(Buffer.from('8801023137', 'hex'))
expect(data[0]).to.be.eql(Buffer.from('880102', 'hex'))
})
)
})
Expand Down

0 comments on commit 55d096e

Please sign in to comment.