Skip to content

fix(coverage): one line counter for a source buffer (#1967) - #2336

Open
DeusData wants to merge 2 commits into
mainfrom
fix/issue-1967
Open

DeusData wants to merge 2 commits into
mainfrom
fix/issue-1967

Conversation

@DeusData

Copy link
Copy Markdown
Owner

Three places in internal/cbm/cbm.c counted the lines of the same source
buffer with two different conventions. cbm_count_lines (parse_unusable
80% threshold) ignored a final newline, while the inline counter that
sizes the preprocessed-line map (orig_lines) and cbm_line_offsets (the
recovery-gap walker) counted every newline, so on any file ending in a
newline -- nearly every file -- they disagreed by one.

Nothing produced a wrong answer: every consumer of the larger count
either clamps to it or sees the phantom last line as blank. The risk
was the next reader picking up one convention without knowing the
other existed.

Add cbm_source_line_count() as the single helper, with the convention
documented beside it: a '\n' terminates a line and opens no new one;
an empty buffer counts as 1 line. All three call sites use it; the
old static cbm_count_lines is gone.

Test: parse_coverage::source_line_count_one_convention pins the
convention (trailing newline, no final newline, CRLF, empty buffer,
blank last line, src_len bound).

Fixes #1967

Three places in internal/cbm/cbm.c counted the lines of the same source
buffer with two different conventions. cbm_count_lines (parse_unusable
80% threshold) ignored a final newline, while the inline counter that
sizes the preprocessed-line map (orig_lines) and cbm_line_offsets (the
recovery-gap walker) counted every newline, so on any file ending in a
newline -- nearly every file -- they disagreed by one.

Nothing produced a wrong answer: every consumer of the larger count
either clamps to it or sees the phantom last line as blank. The risk
was the next reader picking up one convention without knowing the
other existed.

Add cbm_source_line_count() as the single helper, with the convention
documented beside it: a '\n' terminates a line and opens no new one;
an empty buffer counts as 1 line. All three call sites use it; the
old static cbm_count_lines is gone.

Test: parse_coverage::source_line_count_one_convention pins the
convention (trailing newline, no final newline, CRLF, empty buffer,
blank last line, src_len bound).

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cleanup(coverage): two line counters for the same buffer disagree by one on a trailing newline

1 participant