Skip to content

Fix potential stack overflow in overset initialisation#405

Open
A-CGray wants to merge 1 commit into
mainfrom
bugfix-oversetSegfault
Open

Fix potential stack overflow in overset initialisation#405
A-CGray wants to merge 1 commit into
mainfrom
bugfix-oversetSegfault

Conversation

@A-CGray

@A-CGray A-CGray commented Jun 22, 2026

Copy link
Copy Markdown
Member

Purpose

I have ADflow compiled locally with -Ofast optimisations and was running into segfaults when trying to run certain overset meshes. Turns out -Ofast enables the -fstack-arrays flag, which causes gfortran to allocate the memory for arrays on the stack, even when it doesn't know their size. Depending on the size on the size of your mesh, and the number of cores you're working with, some of the code in the overset utils ends up allocating arrays on the stack which are too large (the default limit is 8mb apparently), leading to a stack overflow.

This PR fixes the issue by switching one of the problematic array copies to an explicit do loop, and replaces the other ones with array reallocation utility routines that are already in the code (that also use an explicit do loop).

This shouldn't be a commonly encountered issue because it only happens with -Ofast and relatively high (~150k) cell counts per core.

Expected time until merged

Soon

Type of change

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (non-backwards-compatible fix or feature)
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Documentation update
  • Maintenance update
  • Other (please describe)

Testing

Checklist

  • I have run ruff check and ruff format to make sure the Python code adheres to PEP-8 and is consistently formatted
  • I have formatted the Fortran code with fprettify or C/C++ code with clang-format as applicable
  • I have run unit and regression tests which pass locally with my changes
  • I have added new tests that prove my fix is effective or that my feature works
  • I have added necessary documentation

@A-CGray A-CGray requested a review from a team as a code owner June 22, 2026 02:24
@A-CGray A-CGray requested review from anilyil and sanjan98 June 22, 2026 02:24
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.

1 participant