Skip to content

Fix segfault when coverage runs with annotations disabled#2552

Merged
joelhawksley merged 1 commit intoViewComponent:mainfrom
george-bit:fix-coverage-segfault-v2
Feb 12, 2026
Merged

Fix segfault when coverage runs with annotations disabled#2552
joelhawksley merged 1 commit intoViewComponent:mainfrom
george-bit:fix-coverage-segfault-v2

Conversation

@george-bit
Copy link
Contributor

Summary

Sorry about this - the fix I submitted in #2541 didn't fully solve the problem. It turns out there's still a segfault when coverage is running but template annotations are disabled.

What went wrong

When I tested locally, annotations were enabled by default, so everything worked. I didn't realise that in most CI environments (including ours!), annotations are typically disabled. This meant the fix only covered one scenario.

The condition I wrote was too restrictive:

if coverage_running? && ActionView::Base.annotate_rendered_view_with_filenames

This only avoided the negative lineno when both conditions were true. When annotations are disabled (common in CI), it still used lineno = -1, which causes the segfault.

The fix

Always use lineno = 0 when coverage is running, regardless of annotation settings:

if coverage_running?
  @strip_annotation_line = ActionView::Base.annotate_rendered_view_with_filenames
  0
else
  -1
end

The annotation line stripping still only happens when annotations are enabled (since there's nothing to strip otherwise), but we avoid the dangerous negative lineno either way.

Added test

I've added a test specifically for the annotations-disabled case. Unfortunately the segfault only reproduces on Linux, not macOS, so I couldn't verify locally - but it would have caught this if it had been in the original PR.

Again, apologies for not getting this right the first time.

The fix in v4.3.0 only avoided negative lineno when BOTH coverage was
running AND annotations were enabled. This still caused segfaults when
coverage was running but annotations were disabled (the common case in
CI environments).

The fix: always use lineno=0 when coverage is running, regardless of
annotation settings. The annotation line stripping is still conditional
on annotations being enabled (since there's nothing to strip otherwise).

Before (v4.3.0):
  coverage + annotations → lineno=0 ✓
  coverage + no annotations → lineno=-1 → SEGFAULT

After:
  coverage + annotations → lineno=0, strip line ✓
  coverage + no annotations → lineno=0 ✓

Added regression test for the annotations-disabled case.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@george-bit george-bit force-pushed the fix-coverage-segfault-v2 branch from 12ee3a1 to ea51de7 Compare February 12, 2026 11:03
@joelhawksley joelhawksley merged commit 5ded019 into ViewComponent:main Feb 12, 2026
14 checks passed
@joelhawksley
Copy link
Member

Thanks for the quick fix!

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.

2 participants