Skip to content

Commit

Permalink
Fix infinite loop for 0- and 1-byte input.
Browse files Browse the repository at this point in the history
  • Loading branch information
eustas committed Jan 18, 2021
1 parent 570216a commit 3e4f537
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ <h2 class="w3-wide">Demo</h2>
let ctx = document.getElementById('canvas').getContext('2d');
ctx.clearRect(0, 0, 64, 64);
let encoded = new Uint8Array(Array.from(atob(input.value)).map(s => s.codePointAt(0)));
ctx.putImageData(window.decode2im(encoded), 0, 0);
let pixels = window.decode2im(encoded);
if ((pixels.width == 64) && (pixels.height == 64)) {
let image = new ImageData(pixels.rgba, pixels.width);
ctx.putImageData(image, 0, 0);
}
}
function onCopyClick(id) {
let src = document.getElementById(id);
Expand Down
2 changes: 1 addition & 1 deletion docs/twim.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/XRangeDecoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export let init = (data) => {
//_state = 1;
//_pos = 0;
//for (let /** @type{number} */ i = 0; i < 16; ++i) _state = (_state * 2) + readBit();
_state = b16 + _data[0] + data[1] * b8;
_state = ((_data[0] + _data[1] * b8) | 0) + b16;
_pos = 16;
};

Expand Down
2 changes: 1 addition & 1 deletion node/twim-decode/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node/twim-decode/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twim-decode",
"version": "1.0.1",
"version": "1.0.2",
"description": "twin decoder",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 3e4f537

Please sign in to comment.