From feab3615594afaabf2ea8771a9a73a5cd14bf649 Mon Sep 17 00:00:00 2001 From: Beldaa Date: Sat, 18 Apr 2026 16:45:21 +0200 Subject: [PATCH] Fix operator precedence in TextLine.HitTest line-break check The paragraph separator (0x2029) check bypassed the Length > 0 guard due to && binding tighter than ||. This could cause an IndexOutOfRangeException when hit-testing near paragraph separators with empty code point runs. --- Topten.RichTextKit/TextLine.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Topten.RichTextKit/TextLine.cs b/Topten.RichTextKit/TextLine.cs index 18cdf52..8b8a5ce 100644 --- a/Topten.RichTextKit/TextLine.cs +++ b/Topten.RichTextKit/TextLine.cs @@ -1,4 +1,4 @@ -// RichTextKit +// RichTextKit // Copyright © 2019-2020 Topten Software. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -249,9 +249,8 @@ internal void HitTest(float x, ref HitTestResult htr) if (lastRun.RunKind == FontRunKind.TrailingWhitespace || lastRun.RunKind == FontRunKind.Ellipsis) { if (lastRun.CodePoints.Length > 0 && - (lastRun.CodePoints[lastRun.CodePoints.Length - 1] == '\n') || - (lastRun.CodePoints[lastRun.CodePoints.Length - 1] == 0x2029) - ) + (lastRun.CodePoints[lastRun.CodePoints.Length - 1] == '\n' || + lastRun.CodePoints[lastRun.CodePoints.Length - 1] == 0x2029)) { htr.ClosestCodePointIndex = lastRun.End - 1; return;