Tk Source Code

View Ticket
Login
Ticket UUID: de01e24aa14e6351a02b6407c825e0c11f7fdc92
Title: Text replace command involving selection crashes
Type: Bug Version: 8.6.8
Submitter: danckaert Created on: 2018-06-13 09:54:36
Subsystem: 18. [text] Assigned To: fvogel
Priority: 8 Severity: Severe
Status: Closed Last Modified: 2018-06-16 08:52:56
Resolution: Fixed Closed By: fvogel
    Closed on: 2018-06-16 08:52:56
Description:

The following causes a crash in Tk:

package require Tk
text .t
.t insert end "foo\n"
.t tag add sel 1.0 end
.t replace sel.first sel.last "bar"

User Comments: fvogel added on 2018-06-16 08:52:56:
Fix and new test merged to core-8-6-branch and trunk.

New test merged to revised_text branch (the fix is not needed in that branch, issue is not present).

fvogel added on 2018-06-16 06:24:14:

Interesting. I thought that your remark deserved practical checking and I did.

If, in core-8-6-branch, I apply the patch you propsoed at this time, that is, I apply [c1fe3071], so that the text widget does not delete before the startindex, and I remove that line that was added to fix [62c5b7a1d7], then indeed neither [62c5b7a1d7] nor the present ticket [de01e24aa1] show any problem anymore.

Regarding deletion of the last newline, I believe the revised_text branch has found a way out. Did you see [e8c28f71b7]? Let's follow-up there about the last newline problem, if you don't mind.

Right now, core-8-6-branch and trunk are providing the legacy version of the text widget therefore I'll merge the fix [e73b162c50] for the present ticket.


danckaert added on 2018-06-14 08:06:13:

The proposed fix works for me, thanks.

Note that the reason for [62c5b7a1d7] (and thus indirectly for this ticket) was probably again that delete is allowed to delete before the start index (see [2886436]).


fvogel added on 2018-06-13 20:53:16:
Forgot to tell that the fix proposal passes the entire test suite for the text widget.

fvogel added on 2018-06-13 20:37:16:

Fix proposal: [e73b162c50]

Note: this problem does not happen with the revised text widget. The fix must not be propagated there (but the new test can and should be).


fvogel added on 2018-06-13 11:23:45:

Problem is that line, that was added in this commit in order to fix [62c5b7a1d7].

TkTextGetIndexFromObj() receives "sel.first" as string index, and returns a NULL index because at this stage there is no selection anymore (the replacement already happened, and the selection got deleted by this operation).

So the path is clear: find the correct fix for [62c5b7a1d7], that does not make Tk regress as decribed in the present ticket. Should be easy.

I have added a (currently crashing) test text-8.28 in the bugfix branch. When both text-8.27 and text-8.28 will pass we'll be done with this.


fvogel added on 2018-06-13 10:58:01:
Well spotted, thansk!

Call stack is:

<verbatim>
>	tk86tg.dll!TkTextIndexForwChars(const TkText * textPtr=0x00000000, const TkTextIndex * srcPtr=0x00000000, int charCount=3, TkTextIndex * dstPtr=0x002bfa34, int type=1)  Line 1491 + 0x6 bytes	C
 	tk86tg.dll!TextWidgetObjCmd(void * clientData=0x0080a768, Tcl_Interp * interp=0x00775e78, int objc=5, Tcl_Obj * const * objv=0x0077d1dc)  Line 1496 + 0x1e bytes	C
 	tcl86tg.dll!Dispatch(void * * data=0x007a75dc, Tcl_Interp * interp=0x00775e78, int result=0)  Line 4426 + 0x15 bytes	C
 	tcl86tg.dll!TclNRRunCallbacks(Tcl_Interp * interp=0x00775e78, int result=0, NRE_callback * rootPtr=0x00000000)  Line 4461 + 0x14 bytes	C
 	tcl86tg.dll!TclEvalObjEx(Tcl_Interp * interp=0x00775e78, Tcl_Obj * objPtr=0x007a7920, int flags=131072, const CmdFrame * invoker=0x00000000, int word=0)  Line 6027 + 0x11 bytes	C
 	tcl86tg.dll!Tcl_EvalObjEx(Tcl_Interp * interp=0x00775e78, Tcl_Obj * objPtr=0x007a7920, int flags=131072)  Line 6008 + 0x15 bytes	C
 	tcl86tg.dll!Tcl_RecordAndEvalObj(Tcl_Interp * interp=0x00775e78, Tcl_Obj * cmdPtr=0x007a7920, int flags=131072)  Line 190 + 0x17 bytes	C
 	tcl86tg.dll!StdinProc(void * clientData=0x002bfecc, int mask=2)  Line 822 + 0x12 bytes	C
 	tcl86tg.dll!Tcl_NotifyChannel(Tcl_Channel_ * channel=0x007ab7a0, int mask=2)  Line 8364 + 0x1b bytes	C
 	tcl86tg.dll!ConsoleEventProc(Tcl_Event * evPtr=0x02d6fbe8, int flags=-3)  Line 885 + 0x16 bytes	C
 	tcl86tg.dll!Tcl_ServiceEvent(int flags=-3)  Line 670 + 0xd bytes	C
 	tcl86tg.dll!Tcl_DoOneEvent(int flags=-3)  Line 967 + 0x9 bytes	C
 	tk86tg.dll!Tk_MainLoop()  Line 2148 + 0x11 bytes	C
 	tcl86tg.dll!Tcl_MainExW(int argc=-1, unsigned short * * argv=0x00701bec, int (Tcl_Interp *)* appInitProc=0x004010a0, Tcl_Interp * interp=0x00775e78)  Line 576 + 0x5 bytes	C
 	tclsh86tg.exe!wmain(int argc=1, unsigned short * * argv=0x00701be8)  Line 129 + 0x25 bytes	C
 	tclsh86tg.exe!__tmainCRTStartup()  Line 579 + 0x19 bytes	C
 	tclsh86tg.exe!wmainCRTStartup()  Line 399	C
 	kernel32.dll!75a8f964() 	
 	[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]	
 	ntdll.dll!77bce369() 	
 	ntdll.dll!77bce57b() 	
</verbatim>

This looks not too difficult to fix, at the very first sight. I'll have a look.