fix: stop ASCII subplot save from segfaulting (#2019)#2023
Merged
Conversation
Saving a subplot grid to the ASCII backend crashed with SIGSEGV in
render_subplots. compute_tight_subplot_margins only supports the raster and
PDF backends, so for ASCII it returns ok=.false. and render_subplots takes
the non-tight margin branch. That branch reserves suptitle space with
if (allocated(state%suptitle) .and. len_trim(state%suptitle) > 0)
which relies on short-circuit evaluation that Fortran does not guarantee.
With no suptitle set, len_trim dereferenced the unallocated string.
Split the test into a nested if so len_trim never sees an unallocated
suptitle. Add an ASCII subplot regression test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2019.
Problem
Saving a figure that uses a subplot grid to the ASCII backend
(
savefig('plot.txt')) crashed with a segmentation fault. The same figuresaved fine to PNG/PDF.
Under gdb the fault is a
len_trimon a null string:Root cause:
compute_tight_subplot_marginsonly supports the raster and PDFbackends, so for ASCII it returns
ok=.false.andrender_subplotstakesthe non-tight margin branch. That branch reserves suptitle space with
which relies on short-circuit evaluation that Fortran does not guarantee (and
which the project rules explicitly forbid assuming). With no suptitle set,
len_trimdereferenced the unallocated string. Raster/PDF take the tightpath and skip this block, so they were unaffected.
Fix
Split the compound
.and.into a nestedifsolen_trimnever sees anunallocated
suptitle.Verification
Build (serial to avoid the unrelated fpm parallel-build SIGABRT):
Failing before the fix (minimal 1x2 grid, no suptitle, save to .txt):
Passing after the fix:
Added
test/ascii/test_ascii_subplots_2019.f90, which saves a subplot grid(no suptitle) to ASCII and asserts the file is written and non-empty.
Related ASCII/subplot tests pass:
test_ascii,test_subplots,test_suptitle,test_utf8_text_preprocessing. Rendering gate(
make verify-artifacts) passes.