From 50cb3c9db38e6cc65f03ebcabadb15545b8a2ad1 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Wed, 11 Jan 2017 22:39:08 +0100 Subject: [PATCH] Pebble: remove null termination from cstrings when converting to json for PebbleKit --- .../gadgetbridge/service/devices/pebble/PebbleProtocol.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java index 25c5cf2a..0a2d7cde 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java @@ -1783,6 +1783,9 @@ public class PebbleProtocol extends GBDeviceProtocol { byte type = buf.get(); short length = buf.getShort(); jsonObject.put("key", key); + if (type == TYPE_CSTRING) { + length--; + } jsonObject.put("length", length); switch (type) { case TYPE_UINT: @@ -1815,6 +1818,7 @@ public class PebbleProtocol extends GBDeviceProtocol { } else { jsonObject.put("type", "string"); jsonObject.put("value", new String(bytes)); + buf.get(); // skip null-termination; } break; default: