Tk Source Code

View Ticket
Login
Ticket UUID: f39133da29604cd301d357c8f393dd90cc284019
Title: Revised [text]: undoing a tag priority change releases the tag twice
Type: Bug Version: revised_text
Submitter: nab Created on: 2026-10-11 12:41:57
Subsystem: 18. [text] Assigned To: nobody
Priority: 5 Medium Severity: Important
Status: Closed Last Modified: 2026-10-11 12:46:47
Resolution: Fixed Closed By: nab
    Closed on: 2026-10-11 12:46:47
Description:

In the revised text widget, undoing tag raise or tag lower makes the tag lose one reference too many. With a debug build (--enable-symbols), this script fails !tagPtr->recentChangePriorityToken in TkTextReleaseTag at the second undo:

text .t -undo 1
.t tag configure B
.t tag configure P
.t tag raise B
.t edit undo
.t edit redo
.t edit undo

and this one fails tagPtr->refCount > 1 || !tagPtr->rootPtr in TkTextReleaseTag when the widget is destroyed:

text .t -undo 1
.t tag configure B
.t tag configure P
.t tag raise B
.t edit undo
.t insert 1.0 x B
destroy .t

Without assertions, the reference count of the tag drops to zero while the text still uses it.

UndoChangeTagPriorityPerform calls ChangeTagPriority with undo set, so replaying the token creates a second, retained token for the same change, and it always gives the reused token the redo type. UndoChangeTagPriorityDestroy ignores its reused argument and releases the tag even when the token lives on as the redo item. The undo tokens of marks (UndoToggleGravityPerform, UndoMoveMarkPerform) do it the other way: no new undo item while replaying, the type depends on isRedo, and no release when the token is reused.

Fix in branch nab-tag-priority-undo, with test textTag-20.1 (raise, undo, redo, undo, then destroy; without the fix it fails the assertion at the second undo). On a debug build on macOS, text*.test pass, and a fuzzer that mixes tag priority changes with undo and redo no longer fails in TkTextReleaseTag.

User Comments: nab added on 2026-10-11 12:46:47:

Merged into revised_text with [d42058c412|d42058c412].