#37 fix signed byte type math
authorKevin Lamonte <kevin.lamonte@gmail.com>
Fri, 8 Feb 2019 16:07:03 +0000 (10:07 -0600)
committerKevin Lamonte <kevin.lamonte@gmail.com>
Fri, 8 Feb 2019 16:07:03 +0000 (10:07 -0600)
src/jexer/net/TelnetInputStream.java

index 056a7dc8e4e10ad2a4d8981f6c1668e1e0422c80..ac010e8f0ab3db06f9c5a038e0ae2464ec209216 100644 (file)
@@ -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;