diff options
author | Ajay Panicker <apanicke@google.com> | 2016-01-07 16:05:11 -0800 |
---|---|---|
committer | The Android Automerger <android-build@google.com> | 2016-02-16 12:28:33 -0800 |
commit | b026d70378fa286249223924f3e144a6a3ab4b7c (patch) | |
tree | f6e4d5ff3f8dc33bf49b9e35bdac97ce0442d07f | |
parent | fb02583acdfb7047795005bb5d27f0db1dfd4c5e (diff) | |
download | android_packages_apps_Bluetooth-b026d70378fa286249223924f3e144a6a3ab4b7c.tar.gz android_packages_apps_Bluetooth-b026d70378fa286249223924f3e144a6a3ab4b7c.tar.bz2 android_packages_apps_Bluetooth-b026d70378fa286249223924f3e144a6a3ab4b7c.zip |
[DO NOT MERGE ANYWHERE] Null terminate MAP instance information
Bug: 26437927
Change-Id: I673de7f7c68b9a02b234bb99c6f89c7fc36f90c9
-rwxr-xr-x | src/com/android/bluetooth/map/BluetoothMapUtils.java | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/com/android/bluetooth/map/BluetoothMapUtils.java b/src/com/android/bluetooth/map/BluetoothMapUtils.java index 66ceecc28..f10c4ec00 100755 --- a/src/com/android/bluetooth/map/BluetoothMapUtils.java +++ b/src/com/android/bluetooth/map/BluetoothMapUtils.java @@ -394,15 +394,16 @@ public class BluetoothMapUtils { static public byte[] truncateUtf8StringToBytearray(String utf8String, int maxLength) throws UnsupportedEncodingException { - byte[] utf8Bytes = null; + byte[] utf8Bytes = new byte[utf8String.length() + 1]; try { - utf8Bytes = utf8String.getBytes("UTF-8"); + System.arraycopy(utf8String.getBytes("UTF-8"), 0, + utf8Bytes, 0, utf8String.length()); } catch (UnsupportedEncodingException e) { Log.e(TAG,"truncateUtf8StringToBytearray: getBytes exception ", e); throw e; } - if (utf8Bytes.length > (maxLength - 1)) { + if (utf8Bytes.length > maxLength) { /* if 'continuation' byte is in place 200, * then strip previous bytes until utf-8 start byte is found */ if ( (utf8Bytes[maxLength - 1] & 0xC0) == 0x80 ) { |