Terminal: Fix endless loop

An error in the QPoint constructor version of CellIterator meant
that m_pos could be bigger than m_maxpos.

CellIterator(,State) was also simplified to be more correct.

Change-Id: Ib67b26695fae1e1857d106319037ca8f63bcb250
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Marcus Tillmanns
2023-05-09 07:37:30 +02:00
parent c0f0ccdc78
commit b509e5aef9
3 changed files with 11 additions and 23 deletions

View File

@@ -10,18 +10,8 @@
namespace Terminal::Internal { namespace Terminal::Internal {
CellIterator::CellIterator(const TerminalSurface *surface, QPoint pos) CellIterator::CellIterator(const TerminalSurface *surface, QPoint pos)
: m_state(State::INSIDE) : CellIterator(surface, pos.x() + (pos.y() * surface->liveSize().width()))
, m_surface(surface) {}
{
m_pos = (pos.x()) + (pos.y() * surface->liveSize().width());
if (m_pos < 0)
m_pos = 0;
if (m_pos == 0)
m_state = State::BEGIN;
m_maxpos = surface->fullSize().width() * (surface->fullSize().height()) - 1;
updateChar();
}
CellIterator::CellIterator(const TerminalSurface *surface, int pos) CellIterator::CellIterator(const TerminalSurface *surface, int pos)
: m_state(State::INSIDE) : m_state(State::INSIDE)
@@ -29,24 +19,22 @@ CellIterator::CellIterator(const TerminalSurface *surface, int pos)
{ {
m_maxpos = surface->fullSize().width() * (surface->fullSize().height()) - 1; m_maxpos = surface->fullSize().width() * (surface->fullSize().height()) - 1;
m_pos = qMax(0, qMin(m_maxpos + 1, pos)); m_pos = qMax(0, qMin(m_maxpos + 1, pos));
if (m_pos == 0) {
if (m_pos == 0)
m_state = State::BEGIN; m_state = State::BEGIN;
} else if (m_pos == m_maxpos + 1) { else if (m_pos == m_maxpos + 1)
m_state = State::END; m_state = State::END;
}
updateChar(); updateChar();
} }
CellIterator::CellIterator(const TerminalSurface *surface, State state) CellIterator::CellIterator(const TerminalSurface *surface)
: m_state(state) : m_state(State::END)
, m_surface(surface) , m_surface(surface)
, m_pos()
{ {
m_maxpos = surface->fullSize().width() * (surface->fullSize().height()) - 1; m_maxpos = surface->fullSize().width() * (surface->fullSize().height()) - 1;
if (state == State::END) {
m_pos = m_maxpos + 1; m_pos = m_maxpos + 1;
} }
}
QPoint CellIterator::gridPos() const QPoint CellIterator::gridPos() const
{ {

View File

@@ -26,7 +26,7 @@ public:
public: public:
CellIterator(const TerminalSurface *surface, QPoint pos); CellIterator(const TerminalSurface *surface, QPoint pos);
CellIterator(const TerminalSurface *surface, int pos); CellIterator(const TerminalSurface *surface, int pos);
CellIterator(const TerminalSurface *surface, State state); CellIterator(const TerminalSurface *surface);
public: public:
QPoint gridPos() const; QPoint gridPos() const;

View File

@@ -496,7 +496,7 @@ CellIterator TerminalSurface::begin() const
CellIterator TerminalSurface::end() const CellIterator TerminalSurface::end() const
{ {
return CellIterator(this, CellIterator::State::END); return CellIterator(this);
} }
std::reverse_iterator<CellIterator> TerminalSurface::rbegin() const std::reverse_iterator<CellIterator> TerminalSurface::rbegin() const