jacobslusser / ScintillaNET

A Windows Forms control, wrapper, and bindings for the Scintilla text editor.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

  1. I select desired string with TargetStart and TargetEnd.
  2. I perform a successful SearchInTarget
  3. I call the method ReplaceTarget("")
    An assert is called from SCI_REPLACETARGET in SciLexer 3.7.2\src\Editor.cxx, because of PLATFORM_ASSERT(lParam);
    The reason is because text is empty in public unsafe int ReplaceTarget(string text) and it translates to bytes and IntPtr of null.
        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ý