1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2025-01-24 08:37:32 +01:00

Bangle.js - fix issue where a newline right at the beginning of a received string could cause "String index out of range: -1" errors for all subsequent received data

This commit is contained in:
Gordon Williams 2024-03-13 09:52:03 +00:00
parent fe2a760891
commit f91156cd3e

View File

@ -1025,7 +1025,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
receivedLine += packetStr; receivedLine += packetStr;
while (receivedLine.contains("\n")) { while (receivedLine.contains("\n")) {
int p = receivedLine.indexOf("\n"); int p = receivedLine.indexOf("\n");
String line = receivedLine.substring(0,p-1); String line = receivedLine.substring(0,(p>0) ? (p-1) : 0);
receivedLine = receivedLine.substring(p+1); receivedLine = receivedLine.substring(p+1);
handleUartRxLine(line); handleUartRxLine(line);
} }