Fix mutate 13 error for input sizes longer than 127 bytes
As described on issue #6 (closed), the mutate 13(Replace an ascii digit with another digit) didn't work for input longer than 127 bytes.
The issue was happening because of the integer to byte conversion here:
for (int k=0; k<res.length; k++) {
if (res[k] >= 48 && res[k] <= 57) {
digits.add((byte)k);
}
}
Convert an integer longer than 127 to byte could result in a negative value.
int integerValue = 128;
byte byteValue = (byte)integerValue;
System.out.println(byteValue);
-128
Process finished with exit code 0
The negative value was being used as index of the res
array, causing the index out of bonds exception.
int pos = this.rand(digits.size());
int was = res[digits.get(pos)];
This Merge request fix this issue.
How to run the tests
To run the unit test added on this MR is necessary to update the Corpus.java file. The line 160 should be updated from
int x = this.rand(16);
to
int x = 13;
This change is necessary to force the method mutate to use the variant 13.
Screenshots
Running the tests with old version
Running the tests with the new version
Edited by Marcos Rocha