Attachment "499f8e33.diff" to
ticket [499f8e33]
added by
chrstphrchvz
2023-11-04 08:16:36.
diff --git generic/tkTextBTree.c generic/tkTextBTree.c
index 533f1bf5a..c7061a929 100644
--- generic/tkTextBTree.c
+++ generic/tkTextBTree.c
@@ -632,10 +632,17 @@ AdjustStartEndRefs(
i++;
}
treePtr->startEndCount = count;
- treePtr->startEnd = (TkTextLine **)ckrealloc(treePtr->startEnd,
- sizeof(TkTextLine *) * count);
- treePtr->startEndRef = (TkText **)ckrealloc(treePtr->startEndRef,
- sizeof(TkText *) * count);
+ if (count > 0) {
+ treePtr->startEnd = (TkTextLine **)ckrealloc(treePtr->startEnd,
+ sizeof(TkTextLine *) * count);
+ treePtr->startEndRef = (TkText **)ckrealloc(treePtr->startEndRef,
+ sizeof(TkText *) * count);
+ } else {
+ ckfree(treePtr->startEndRef);
+ treePtr->startEndRef = NULL;
+ ckfree(treePtr->startEnd);
+ treePtr->startEnd = NULL;
+ }
}
if ((action & TEXT_ADD_REFS)
&& (textPtr->start != NULL || textPtr->end != NULL)) {