# Broken WS_BLANK_AT_EOF highlighting with 0-length diff hunks

1 messages from 2025-10-27 to 2025-10-27. Participants: Alice Carlotti.
Thread: https://gitlist.dev/t/64391

## Alice Carlotti, 2025-10-27 13:20

Subject: Broken WS_BLANK_AT_EOF highlighting with 0-length diff hunks
Message-ID: <5447f4f0-68be-b554-9fde-579a8dac69ff@e124511.cambridge.arm.com>
URL: https://gitlist.dev/e/5447f4f0-68be-b554-9fde-579a8dac69ff%40e124511.cambridge.arm.com

```
Whitespace error highlighting is missing for blank lines at end of file when
the final hunk contains either zero old lines or zero new lines.  This most
commonly occurs with new files (which happens to be when WS_BLANK_AT_EOF errors
are most likely to be introduced), but can also occur with -U0.

The reason for this is that the initial line number in a hunk header is reduced
by one for zero length ranges.  In particular, an empty file uses 0,0 whereas a
full nonempty file uses 1,N.  This discrepancy is deliberate, and was agreed in
https://lore.kernel.org/git/7vbqvictsc.fsf@assigned-by-dhcp.cox.net/.

We currently parse the hunk headers in diff.c:find_lno().  We could therefore
fix the bug here by incrementing lno_in_{pre|post}image whenever the
corresponding length is zero.  Parsing the full ranges is complicated, but I
notice that there is code to do this in apply.c:parse_range() - perhaps this
code could be copied or reused?
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

```
