Files
codebase-memory-mcp/tests
Martin Vogel 14ed8ce38a fix(coverage): one line counter for a source buffer (#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>
2026-10-04 18:21:44 +02:00
..