Skip to content

Operator precedence bug in TextLine.HitTest paragraph separator check #111

@Beldaa

Description

@Beldaa

In TextLine.HitTest() (TextLine.cs, around line 251), the check for paragraph separator (0x2029) has an operator precedence issue.

Current code:

if (lastRun.CodePoints.Length > 0 && 
    (lastRun.CodePoints[lastRun.CodePoints.Length - 1] == '\n') ||
    (lastRun.CodePoints[lastRun.CodePoints.Length - 1] == 0x2029)
    )

Because && binds more tightly than ||, this is parsed as:

(Length > 0 && cp == '\n') || (cp == 0x2029)

The 0x2029 check bypasses the Length > 0 guard entirely. If CodePoints.Length is 0, the second part CodePoints[Length - 1] would still be evaluated, indexing at -1 and causing an IndexOutOfRangeException.

It should be:

if (lastRun.CodePoints.Length > 0 && 
    (lastRun.CodePoints[lastRun.CodePoints.Length - 1] == '\n' ||
     lastRun.CodePoints[lastRun.CodePoints.Length - 1] == 0x2029))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions