Author: sagamusix
Date: Sun Mar 3 17:33:22 2024
New Revision: 20221
URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=20221
Log:
[Fix] Previous revision could crash when trying to insert a pattern sequence at the end of the order list when the pattern sequence itself ended with "---" patterns.
Modified:
trunk/OpenMPT/soundlib/ModSequence.cpp
trunk/OpenMPT/soundlib/ModSequence.h
Modified: trunk/OpenMPT/soundlib/ModSequence.cpp
==============================================================================
--- trunk/OpenMPT/soundlib/ModSequence.cpp Sun Mar 3 17:11:37 2024 (r20220)
+++ trunk/OpenMPT/soundlib/ModSequence.cpp Sun Mar 3 17:33:22 2024 (r20221)
@@ -101,10 +101,12 @@
}
-ORDERINDEX ModSequence::GetRemainingCapacity() const noexcept
+ORDERINDEX ModSequence::GetRemainingCapacity(ORDERINDEX startingFrom) const noexcept
{
const auto &specs = m_sndFile.GetModSpecifications();
- const ORDERINDEX length = GetLengthTailTrimmed();
+ ORDERINDEX length = GetLengthTailTrimmed();
+ if(startingFrom != ORDERINDEX_INVALID && startingFrom > length)
+ length = startingFrom;
if(length >= specs.ordersMax)
return 0;
else
@@ -198,7 +200,7 @@
{
const auto ordersMax = m_sndFile.GetModSpecifications().ordersMax;
// Limit number of orders to be inserted so that we don't exceed the format limit or drop items at the end of the order list.
- LimitMax(count, GetRemainingCapacity());
+ LimitMax(count, GetRemainingCapacity(pos));
if(pos >= ordersMax || GetLengthTailTrimmed() >= ordersMax || count == 0)
return 0;
reserve(std::max(pos, GetLength()) + count);
Modified: trunk/OpenMPT/soundlib/ModSequence.h
==============================================================================
--- trunk/OpenMPT/soundlib/ModSequence.h Sun Mar 3 17:11:37 2024 (r20220)
+++ trunk/OpenMPT/soundlib/ModSequence.h Sun Mar 3 17:33:22 2024 (r20221)
@@ -49,7 +49,7 @@
// Returns length of sequence stopping counting on first '---' (or at the end of sequence).
ORDERINDEX GetLengthFirstEmpty() const noexcept;
// Returns amount of patterns that can be added at the end of the order list before reaching the current format's limits.
- ORDERINDEX GetRemainingCapacity() const noexcept;
+ ORDERINDEX GetRemainingCapacity(ORDERINDEX startingFrom = ORDERINDEX_INVALID) const noexcept;
// Replaces order list with 'newSize' copies of 'pat'.
void assign(ORDERINDEX newSize, PATTERNINDEX pat);
|