Skip to content

Conversation

@krystophny
Copy link
Collaborator

Summary

  • Fixes critical CI segmentation faults in colored_contours and ascii_heatmap_demo examples
  • Replaces unsafe merge() function usage with conditional parameter forwarding in matplotlib wrapper
  • Adds comprehensive regression tests to prevent future memory safety issues

Root Cause Analysis

The segfaults were caused by improper usage of the merge() intrinsic function when forwarding optional parameters to underlying methods. When optional parameters were not present, merge() was still trying to pass zero-size allocated arrays, causing memory access violations.

Technical Details

Fixed Functions:

  • contour_filled() in fortplot_matplotlib.f90 (line 112)
  • add_contour_filled() in fortplot_matplotlib.f90 (line 437)

Memory Safety Improvements:

  • Replace merge(wp_levels, wp_levels, present(levels)) with conditional parameter forwarding
  • Prevent passing uninitialized zero-size arrays to underlying methods
  • Use explicit if/else chains to handle all parameter combinations safely

Testing

  • ✅ colored_contours example runs without segfault
  • ✅ ascii_heatmap_demo example runs without segfault
  • ✅ pcolormesh_demo example continues to work correctly
  • ✅ Added targeted regression test test_contour_memory_safety_regression.f90
  • ✅ All existing tests continue to pass

Impact

This fix unblocks all PR merges that were prevented by CI failures. The examples now complete successfully and produce expected output files.

🤖 Generated with Claude Code

krystophny and others added 2 commits August 26, 2025 17:20
Replace unsafe merge() function usage in matplotlib wrapper with conditional
calls to prevent memory access violations. The merge() function was causing
segfaults when optional parameters were not present, particularly in
colored_contours and ascii_heatmap_demo examples.

Memory safety improvements:
- Replace merge() with explicit conditional parameter forwarding
- Fix both contour_filled() and add_contour_filled() functions
- Prevent passing uninitialized zero-size arrays to underlying methods
- Add comprehensive regression tests to prevent future occurrences

Fixes critical CI blocking issue where examples crashed with SIGSEGV.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Aug 26, 2025

Codecov Report

❌ Patch coverage is 0% with 109 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/fortplot_matplotlib.f90 0.00% 58 Missing ⚠️
test/test_contour_memory_safety_regression.f90 0.00% 51 Missing ⚠️

📢 Thoughts on this report? Let us know!

@krystophny krystophny merged commit 4648d09 into main Aug 26, 2025
5 checks passed
@krystophny krystophny deleted the fix-ci-segfaults-401 branch August 26, 2025 15:47
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