mirror of
https://github.com/haven1433/HexManiacAdvance.git
synced 2026-05-20 12:18:04 -05:00
Don't crash when copying a bit-field with unknown set bits
This commit is contained in:
parent
c422f8bff2
commit
c9ddab7ae3
|
|
@ -509,9 +509,17 @@ namespace HavenSoft.HexManiac.Core.Models.Runs {
|
|||
var result = new StringBuilder("-");
|
||||
var options = rawData.GetBitOptions(SourceArrayName);
|
||||
|
||||
// handle edge cases: no options, or no options for some set bits
|
||||
var highestByteSet = Length - 1;
|
||||
while (rawData[offset + highestByteSet] == 0 && highestByteSet > 0) {
|
||||
highestByteSet -= 1;
|
||||
}
|
||||
var highestBitSet = (int)Math.Log(rawData[offset + highestByteSet], 2);
|
||||
var unknownBitsAreSet = options == null || (highestByteSet * 8) + highestBitSet >= options.Count;
|
||||
|
||||
for (int i = 0; i < Length; i++) {
|
||||
var bits = rawData[offset + i];
|
||||
if (options == null) {
|
||||
if (unknownBitsAreSet) {
|
||||
result.Append(bits.ToString("X2"));
|
||||
} else {
|
||||
var optionOffset = i << 3;
|
||||
|
|
|
|||
|
|
@ -1091,6 +1091,21 @@ namespace HavenSoft.HexManiac.Tests {
|
|||
Assert.True(match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BitFieldWithUnknownBitSet_CopyPaste_CorrectBitsSet() {
|
||||
var fileSystem = new StubFileSystem();
|
||||
Model.SetList(new ModelDelta(), "bits", "adam", "bob", "carl", "dave");
|
||||
ViewPort.Edit("^table[a|b[]bits]3 00 10 ");
|
||||
|
||||
ViewPort.SelectionStart = new Point(1, 0);
|
||||
ViewPort.Copy.Execute(fileSystem);
|
||||
|
||||
ViewPort.SelectionStart = new Point(2, 0);
|
||||
ViewPort.Edit(fileSystem.CopyText);
|
||||
|
||||
Assert.Equal(0x10, Model[2]);
|
||||
}
|
||||
|
||||
private static void StandardSetup(out byte[] data, out PokemonModel model, out ViewPort viewPort) {
|
||||
data = new byte[0x200];
|
||||
model = new PokemonModel(data);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user