Debugger: Prevent overwriting an existing label when trying to add a multibyte label over it

This commit is contained in:
Sour 2019-01-22 20:47:43 -05:00
parent 55dc91e60c
commit 681c695d0b

View file

@ -67,8 +67,6 @@ namespace Mesen.GUI.Debugger
UInt32 length = ((CodeLabel)Entity).Length;
AddressType type = ((CodeLabel)Entity).AddressType;
CodeLabel sameLabel = LabelManager.GetLabel(txtLabel.Text);
CodeLabel sameAddress = LabelManager.GetLabel(address, type);
int maxAddress = GetMaxAddress(type);
if(maxAddress <= 0) {
@ -77,11 +75,26 @@ namespace Mesen.GUI.Debugger
lblRange.Text = "($0000 - $" + maxAddress.ToString("X4") + ")";
}
for(UInt32 i = 0; i < length; i++) {
CodeLabel sameAddress = LabelManager.GetLabel(address + i, type);
if(sameAddress != null) {
if(_originalLabel == null) {
//A label already exists and we're not editing an existing label, so we can't add it
return false;
} else {
if(sameAddress.Label != _originalLabel.Label && !sameAddress.Label.StartsWith(_originalLabel.Label + "+")) {
//A label already exists, we're trying to edit an existing label, but the existing label
//and the label we're editing aren't the same label. Can't override an existing label with a different one.
return false;
}
}
}
}
return
length >= 1 && length <= 65536 &&
address + (length - 1) <= maxAddress &&
(sameLabel == null || sameLabel == _originalLabel)
&& (sameAddress == null || sameAddress == _originalLabel)
&& (_originalLabel != null || txtLabel.Text.Length > 0 || txtComment.Text.Length > 0)
&& !txtComment.Text.Contains('\x1')
&& (txtLabel.Text.Length == 0 || LabelManager.LabelRegex.IsMatch(txtLabel.Text));