Quick fix for AppleUtil#getWordValue to handle upper edge of buffer correctly. #126
This commit is contained in:
parent
ee981551b9
commit
0c285a7d46
|
@ -60,7 +60,7 @@ public class AppleUtil {
|
||||||
* A word is two bytes, in standard Apple LO/HI format.
|
* A word is two bytes, in standard Apple LO/HI format.
|
||||||
*/
|
*/
|
||||||
public static int getWordValue(byte[] buffer, int offset) {
|
public static int getWordValue(byte[] buffer, int offset) {
|
||||||
if (offset+1 > buffer.length) {
|
if (offset+1 >= buffer.length) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return getWordValue(buffer[offset], buffer[offset+1]);
|
return getWordValue(buffer[offset], buffer[offset+1]);
|
||||||
|
|
|
@ -142,4 +142,15 @@ public class AppleUtilTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetWordValue_beyondEdge() {
|
||||||
|
byte[] data = new byte[] { 0x01, 0x02, 0x03, 0x04 };
|
||||||
|
|
||||||
|
assertEquals(0x0201, AppleUtil.getWordValue(data, 0));
|
||||||
|
assertEquals(0x0302, AppleUtil.getWordValue(data, 1));
|
||||||
|
assertEquals(0x0403, AppleUtil.getWordValue(data, 2));
|
||||||
|
assertEquals(0x0000, AppleUtil.getWordValue(data, 3));
|
||||||
|
assertEquals(0x0000, AppleUtil.getWordValue(data, 4));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue