ReplaceTarget with an empty string leads to an Assertion in SciLexer in Debug Modus
FilipRychnavsky opened this issue · comments
I have a scenario, where I would like to delete some text.
- I select desired string with
TargetStart
andTargetEnd
. - I perform a successful
SearchInTarget
- I call the method ReplaceTarget("")
An assert is called fromSCI_REPLACETARGET
in SciLexer 3.7.2\src\Editor.cxx, because of PLATFORM_ASSERT(lParam);
The reason is becausetext
is empty inpublic unsafe int ReplaceTarget(string text)
and it translates tobytes
andIntPtr
ofnull
.
public unsafe int ReplaceTarget(string text)
{
if (text == null)
text = string.Empty;
var bytes = Helpers.GetBytes(text, Encoding, false);
fixed (byte* bp = bytes)
DirectMessage(NativeMethods.SCI_REPLACETARGET, new IntPtr(bytes.Length), new IntPtr(bp));
return text.Length;
}
Here the Editor.cxx
case SCI_REPLACETARGET:
PLATFORM_ASSERT(lParam);
return ReplaceTarget(false, CharPtrFromSPtr(lParam), static_cast<int>(wParam));
The assertion influences only the debug modus. Everything is fine in release.
Greetings
Filip Rychnavský