Skip to content

Commit 25c1f7b

Browse files
krystophnyclaude
andcommitted
fix: add input validation to prevent runtime errors in rendering functions
Added comprehensive input validation to render_line_plot and render_markers to prevent runtime errors when plot_data arrays are unallocated or empty. This fixes the streamplot_demo crash that was blocking test-coverage CI. - Check if x/y arrays are allocated before accessing - Validate array sizes are non-zero - Ensure x and y arrays have matching sizes - Early return for invalid data instead of crashing Fixes test-coverage CI failure caused by streamplot_demo runtime error. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0878dbb commit 25c1f7b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/fortplot_rendering.f90

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ subroutine render_line_plot(backend, plot_data, plot_idx, x_min_t, x_max_t, y_mi
4040
real(wp), allocatable :: x_scaled(:), y_scaled(:)
4141
integer :: i, n
4242

43+
! Validate input data
44+
if (.not. allocated(plot_data%x) .or. .not. allocated(plot_data%y)) return
45+
if (size(plot_data%x) == 0 .or. size(plot_data%y) == 0) return
46+
if (size(plot_data%x) /= size(plot_data%y)) return
47+
4348
n = size(plot_data%x)
4449
allocate(x_scaled(n), y_scaled(n))
4550

@@ -74,6 +79,11 @@ subroutine render_markers(backend, plot_data, x_min_t, x_max_t, y_min_t, y_max_t
7479
if (.not. allocated(plot_data%marker)) return
7580
if (len_trim(plot_data%marker) == 0) return
7681

82+
! Validate input data
83+
if (.not. allocated(plot_data%x) .or. .not. allocated(plot_data%y)) return
84+
if (size(plot_data%x) == 0 .or. size(plot_data%y) == 0) return
85+
if (size(plot_data%x) /= size(plot_data%y)) return
86+
7787
! Draw markers
7888
call backend%color(plot_data%color(1), plot_data%color(2), plot_data%color(3))
7989

0 commit comments

Comments
 (0)