Skip to content

Bug fix: stop using dangling ptrs and buildPattern() in fixPartitions() - #186

Merged
bqminh merged 1 commit into
iqtree:masterfrom
StefanFlaumberg:fixalignment
Jul 22, 2026
Merged

Bug fix: stop using dangling ptrs and buildPattern() in fixPartitions()#186
bqminh merged 1 commit into
iqtree:masterfrom
StefanFlaumberg:fixalignment

Conversation

@StefanFlaumberg

Copy link
Copy Markdown
Contributor

This pull request fixes two issues in the fixPartitions() function from phylotesting.cpp:

  1. ModelOMatic can change some subalignments effectively through the stree->at(i)->aln pointers. This means that the respective saln->partitions[i] pointers remain dangling, as they cannot be reset in place due to the general code design. Comparison with a dangling pointer has an implementation-specific behaviour in c++, it might work or might not.
    Therefore, I opt to avoid it here simply by unconditionally resetting all saln->partitions pointers and relevant saln info (see below). This means that now the reset happens for each PartitionFinder call, but since it happens only once, the time overhead is negligible.
  2. After my recent alignment refactoring, SuperAlignment::buildPattern() expects that the alignment pattern vector is empty. This guarantees that the function is used only during superalignment initialization, as any other usage would likely be incorrect.
    Here, in fixPartitions(), we change sequence types of subalignments (and hence their pattern numbers and contents), but the patterns of taxon presence/absence remain the same. So saln->taxa_index remains the same as well and it would be pointless to call saln->buildPattern(), even if we could. But since the pattern contents of the subalignments might have changed, we have to call saln->computeConstSites() and saln->orderPatternByNumChars here.

@bqminh bqminh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

@bqminh
bqminh merged commit 43028e8 into iqtree:master Jul 22, 2026
7 checks passed
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