Corrected convertBytesToString with offset and length

This commit is contained in:
ghidra1 2019-05-22 15:00:37 -04:00
parent 146a83f953
commit 4614567590
2 changed files with 10 additions and 2 deletions

View file

@ -670,7 +670,7 @@ public final class NumericUtilities {
*/
public static String convertBytesToString(byte[] bytes, int start, int len, String delimeter) {
Iterator<Byte> iterator = IteratorUtils.arrayIterator(bytes, start, len);
Iterator<Byte> iterator = IteratorUtils.arrayIterator(bytes, start, start + len);
return convertBytesToString(iterator, delimeter);
}

View file

@ -15,7 +15,8 @@
*/
package ghidra.util;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.util.*;
import java.util.stream.Collectors;
@ -95,6 +96,13 @@ public class NumericUtilitiesTest {
assertEquals("012380ff00", str);
}
@Test
public void testConvertBytesToStringWithOffsetAndLength() {
byte[] bytes = new byte[] { (byte) 0x1, (byte) 0x23, (byte) 0x80, (byte) 0xff, (byte) 0 };
String str = NumericUtilities.convertBytesToString(bytes, 2, 2, " ");
assertEquals("80 ff", str);
}
@Test
public void testConvertBytesToStringWithDelimiter() {
byte[] bytes = new byte[] { (byte) 0x1, (byte) 0x23, (byte) 0x80, (byte) 0xff, (byte) 0 };