altosui: Elide nul bytes at end of telemetry string values
authorKeith Packard <keithp@keithp.com>
Wed, 6 Jul 2011 06:35:50 +0000 (23:35 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 6 Jul 2011 06:35:50 +0000 (23:35 -0700)
All telemetry fields are fixed length, so any embedded strings are
padded with nul bytes.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosui/Altos.java

index 37a4f67..3649084 100644 (file)
@@ -240,9 +240,15 @@ public class Altos {
                        }
                }
 
+               int i;
+               for (i = l - 1; i >= 0; i--)
+                       if (bytes[s+i] != 0)
+                               break;
+
+               l = i + 1;
                byte[]  b = new byte[l];
 
-               for (int i = 0; i < l; i++)
+               for (i = 0; i < l; i++)
                        b[i] = (byte) bytes[s+i];
                String n = new String(b, unicode_set);
                return n;