mirror of
https://github.com/Genymobile/scrcpy
synced 2024-11-11 01:10:32 +00:00
Truncate device name at UTF-8 code point boundary
Just in case.
This commit is contained in:
parent
5d11339259
commit
8604f16b30
@ -89,7 +89,7 @@ public final class DesktopConnection implements Closeable {
|
|||||||
byte[] buffer = new byte[DEVICE_NAME_FIELD_LENGTH + 4];
|
byte[] buffer = new byte[DEVICE_NAME_FIELD_LENGTH + 4];
|
||||||
|
|
||||||
byte[] deviceNameBytes = deviceName.getBytes(StandardCharsets.UTF_8);
|
byte[] deviceNameBytes = deviceName.getBytes(StandardCharsets.UTF_8);
|
||||||
int len = Math.min(DEVICE_NAME_FIELD_LENGTH - 1, deviceNameBytes.length);
|
int len = StringUtils.getUtf8TruncationIndex(deviceNameBytes, DEVICE_NAME_FIELD_LENGTH - 1);
|
||||||
System.arraycopy(deviceNameBytes, 0, buffer, 0, len);
|
System.arraycopy(deviceNameBytes, 0, buffer, 0, len);
|
||||||
// byte[] are always 0-initialized in java, no need to set '\0' explicitly
|
// byte[] are always 0-initialized in java, no need to set '\0' explicitly
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user