mirror of
https://github.com/AppleCommander/AppleCommander.git
synced 2024-12-30 16:29:40 +00:00
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.
|
||||
*/
|
||||
public static int getWordValue(byte[] buffer, int offset) {
|
||||
if (offset+1 > buffer.length) {
|
||||
if (offset+1 >= buffer.length) {
|
||||
return 0;
|
||||
}
|
||||
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
Block a user