Skip to content

Commit

Permalink
Assert that m_stemNo is in valid range and log a SKIN_WARNING.
Browse files Browse the repository at this point in the history
Add bounds check for m_stemNo in WStemLabel::slotTrackLoaded
  • Loading branch information
JoergAtGithub committed Sep 21, 2024
1 parent 799867d commit 79e36cc
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/widget/wstemlabel.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "wstemlabel.h"

#include "moc_wstemlabel.cpp"
#include "util/logger.h"

const mixxx::Logger kLogger("WStemLabel");

WStemLabel::WStemLabel(QWidget* pParent)
: WLabel(pParent),
Expand All @@ -10,6 +13,18 @@ WStemLabel::WStemLabel(QWidget* pParent)

void WStemLabel::setup(const QDomNode& node, const SkinContext& context) {
m_stemNo = context.selectInt(node, "StemNum");

VERIFY_OR_DEBUG_ASSERT(m_stemNo >= 1 && m_stemNo <= mixxx::kMaxSupportedStems) {
SKIN_WARNING(node,
context,
QStringLiteral("StemNum is out of range. It should be between "
"1 and %1")
.arg(mixxx::kMaxSupportedStems));
m_stemNo = qBound(1,
m_stemNo,
mixxx::kMaxSupportedStems); // Ensure m_stemNo is within the
// valid range
}
}

void WStemLabel::slotTrackUnloaded(TrackPointer) {
Expand All @@ -28,6 +43,12 @@ void WStemLabel::slotTrackLoaded(TrackPointer pTrack) {
return;
}

VERIFY_OR_DEBUG_ASSERT(m_stemNo <= stemInfo.size()) {
kLogger.warning() << "Stem number out of range. m_stemNo: " << m_stemNo
<< ", stemInfo size: " << stemInfo.size();
return;
}

m_stemInfo = stemInfo[m_stemNo - 1];
updateLabel();
}
Expand Down

0 comments on commit 79e36cc

Please sign in to comment.