From 0895a25ffa531ec5786d8f0b7e0d585d95d8e81e Mon Sep 17 00:00:00 2001 From: Kevin Lamonte Date: Fri, 8 Feb 2019 10:07:03 -0600 Subject: [PATCH] #37 fix signed byte type math --- src/jexer/net/TelnetInputStream.java | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) 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; -- 2.27.0