From: Kevin Lamonte Date: Fri, 8 Feb 2019 16:07:03 +0000 (-0600) Subject: #37 fix signed byte type math X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=0895a25ffa531ec5786d8f0b7e0d585d95d8e81e;p=nikiroo-utils.git #37 fix signed byte type math --- diff --git a/src/jexer/net/TelnetInputStream.java b/src/jexer/net/TelnetInputStream.java index 056a7dc..ac010e8 100644 --- a/src/jexer/net/TelnetInputStream.java +++ b/src/jexer/net/TelnetInputStream.java @@ -926,25 +926,41 @@ public class TelnetInputStream extends InputStream implements SessionInfo { if (subnegBuffer.get(i) == (byte)TELNET_IAC) { i++; } - windowWidth = subnegBuffer.get(i) * 256; + int width = subnegBuffer.get(i); + if (width < 0) { + width += 256; + } + windowWidth = width * 256; i++; if (subnegBuffer.get(i) == (byte)TELNET_IAC) { i++; } - windowWidth += subnegBuffer.get(i); + width = subnegBuffer.get(i); + windowWidth += width; + if (width < 0) { + windowWidth += 256; + } i++; if (subnegBuffer.get(i) == (byte)TELNET_IAC) { i++; } - windowHeight = subnegBuffer.get(i) * 256; + int height = subnegBuffer.get(i); + if (height < 0) { + height += 256; + } + windowHeight = height * 256; i++; if (subnegBuffer.get(i) == (byte)TELNET_IAC) { i++; } - windowHeight += subnegBuffer.get(i); + height = subnegBuffer.get(i); + windowHeight += height; + if (height < 0) { + windowHeight += 256; + } } break;