diff --git a/decode.js b/decode.js index 25605aa..01b5767 100644 --- a/decode.js +++ b/decode.js @@ -9,8 +9,13 @@ function read(buf, offset) { , shift = 0 , counter = offset , b + , l = buf.length do { + if(counter >= l) { + read.bytesRead = 0 + return undefined + } b = buf[counter++] res += shift < 28 ? (b & REST) << shift @@ -18,12 +23,7 @@ function read(buf, offset) { shift += 7 } while (b >= MSB) - if(b === undefined) { - read.bytesRead = 0 - res = undefined - } - else - read.bytesRead = counter - offset + read.bytesRead = counter - offset return res }