summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikayla Ray <mikayla@livioconnect.com>2015-06-23 10:37:11 -0400
committerMikayla Ray <mikayla@livioconnect.com>2015-06-23 10:37:11 -0400
commit304d4b31b9b0cde0bee123425ad15936b8939bf7 (patch)
tree035665427d153a39010821c89673a986ef7da636
parent721dda4d12b8fbf408637636b5126b081dda5727 (diff)
downloadsdl_android-feature/exception_cleanup.tar.gz
Index value moved back, offset checks documented, and byte casting replaced with a safer measure.feature/exception_cleanup
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/util/BitConverter.java13
1 files changed, 9 insertions, 4 deletions
diff --git a/sdl_android_lib/src/com/smartdevicelink/util/BitConverter.java b/sdl_android_lib/src/com/smartdevicelink/util/BitConverter.java
index 2c33b2b5f..93dc8062c 100644
--- a/sdl_android_lib/src/com/smartdevicelink/util/BitConverter.java
+++ b/sdl_android_lib/src/com/smartdevicelink/util/BitConverter.java
@@ -60,9 +60,8 @@ public class BitConverter {
// string can be a subset of those bytes.
length = Math.min(bytes.length, (offset + length));
- for (int binaryArrayIndex = offset; binaryArrayIndex < length; binaryArrayIndex++) {
- int hexArrayIndex = 0;
-
+ int hexArrayIndex = 0;
+ for (int binaryArrayIndex = offset; binaryArrayIndex < length; binaryArrayIndex++) {
// Get a single byte from the array.
byte unit = bytes[binaryArrayIndex];
@@ -82,7 +81,7 @@ public class BitConverter {
byte [] theBytes = new byte[hexString.length() / 2];
for (int i = 0; i < hexString.length(); i += 2) {
String byteString = hexString.substring(i, i + 2);
- byte theByte = (byte)Integer.parseInt(byteString, 16);
+ byte theByte = ((Integer) Integer.parseInt(byteString, 16)).byteValue();
theBytes[i/2] = theByte;
}
return theBytes;
@@ -113,6 +112,9 @@ public class BitConverter {
return 0;
}
+ // If the offset is greater than the length of the array then there are
+ // no values that need to be converted, so the method returns zero. This
+ // avoids a potential ArrayIndexOutOfBoundsException.
if (offset > bytes.length) {
return 0;
}
@@ -143,6 +145,9 @@ public class BitConverter {
return 0;
}
+ // If the offset is greater than the length of the array then there are
+ // no values that need to be converted, so the method returns zero. This
+ // avoids a potential ArrayIndexOutOfBoundsException.
if (offset > bytes.length) {
return 0;
}