Browse Source

ValueDial: fix out of range read in paintEvent while animating

setValue() formatted the new text before clamping the value, so a value
above the maximum produced a text with more digits than the dial and the
dial ended up showing the unclamped value. Format the clamped value
instead.

The current and new texts can still differ in length while animating,
for example when setValueRange() changes the number of digits, so only
compare characters that exist in the new text.

Fixes #2997
chirpmodem-v8.0.0
Wahaj18 1 month ago
parent
commit
4d8ac590a0
  1. 5
      sdrgui/gui/valuedial.cpp

5
sdrgui/gui/valuedial.cpp

@ -115,7 +115,6 @@ void ValueDial::setColorMapper(ColorMapper colorMapper) @@ -115,7 +115,6 @@ void ValueDial::setColorMapper(ColorMapper colorMapper)
void ValueDial::setValue(quint64 value)
{
m_valueNew = value;
m_textNew = formatText(m_valueNew);
if (m_valueNew < m_valueMin) {
m_valueNew = m_valueMin;
@ -123,6 +122,8 @@ void ValueDial::setValue(quint64 value) @@ -123,6 +122,8 @@ void ValueDial::setValue(quint64 value)
m_valueNew = m_valueMax;
}
m_textNew = formatText(m_valueNew);
QAccessibleValueChangeEvent event(this, value);
QAccessible::updateAccessibility(&event);
@ -299,7 +300,7 @@ void ValueDial::paintEvent(QPaintEvent *) @@ -299,7 +300,7 @@ void ValueDial::paintEvent(QPaintEvent *)
{
for (int i = 0; i < m_text.length(); i++)
{
if (m_text[i] == m_textNew[i])
if ((i < m_textNew.length()) && (m_text[i] == m_textNew[i]))
{
painter.setClipRect(1 + i * m_digitWidth, 1, m_digitWidth, m_digitHeight * 2);
painter.setPen(secondaryForegroundColor);

Loading…
Cancel
Save