mirror of
https://github.com/DeusData/codebase-memory-mcp.git
synced 2026-11-12 09:47:20 +08:00
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>