From affceb9ffdb20ad8dafd67654442f0ec05c82fe2 Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Thu, 15 Mar 2012 02:11:03 -0700 Subject: [PATCH] Fix a bug involving the Terminal::finishOutput call. Before the Qt removal, Terminal::finishOutput accepted a QPoint object with a 32-bit line number. Changing it to accept Coord introduced a bug because the Coord line number is only 16-bits. The moveTerminalToLine and sendLine methods still accepted a 32-bit line number, though. The result was, after 32768 lines of output, the Terminal::moveTerminalToLine function would be called alternately with truncated and untruncated line numbers (e.g. -32000 and 33536), and the function would generate massive amounts of "cursor up" and "newline" output. --- agent/Agent.cc | 4 +++- agent/Terminal.cc | 8 ++++---- agent/Terminal.h | 5 +++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/agent/Agent.cc b/agent/Agent.cc index 54eaad1..b70cdf7 100644 --- a/agent/Agent.cc +++ b/agent/Agent.cc @@ -12,6 +12,7 @@ #include #include #include +#include const int SC_CONSOLE_MARK = 0xFFF2; const int SC_CONSOLE_SELECT_ALL = 0xFFF5; @@ -405,7 +406,8 @@ void Agent::scrapeOutput() createSyncMarker(windowRect.top() - 200); } - m_terminal->finishOutput(cursor + Coord(0, m_scrolledCount)); + m_terminal->finishOutput(std::pair(cursor.X, + cursor.Y + m_scrolledCount)); unfreezeConsole(); } diff --git a/agent/Terminal.cc b/agent/Terminal.cc index 54fad0d..70be3ab 100644 --- a/agent/Terminal.cc +++ b/agent/Terminal.cc @@ -43,7 +43,7 @@ void Terminal::reset(bool sendClearFirst, int newLine) m_output->write(CSI"1;1H"CSI"2J"); m_remoteLine = newLine; m_cursorHidden = false; - m_cursorPos = Coord(0, newLine); + m_cursorPos = std::pair(0, newLine); m_remoteColor = -1; } @@ -96,14 +96,14 @@ void Terminal::sendLine(int line, CHAR_INFO *lineData, int width) m_output->write(termLine.data(), termLine.size()); } -void Terminal::finishOutput(const Coord &newCursorPos) +void Terminal::finishOutput(const std::pair &newCursorPos) { if (newCursorPos != m_cursorPos) hideTerminalCursor(); if (m_cursorHidden) { - moveTerminalToLine(newCursorPos.Y); + moveTerminalToLine(newCursorPos.second); char buffer[32]; - sprintf(buffer, CSI"%dG"CSI"?25h", newCursorPos.X + 1); + sprintf(buffer, CSI"%dG"CSI"?25h", newCursorPos.first + 1); m_output->write(buffer); m_cursorHidden = false; } diff --git a/agent/Terminal.h b/agent/Terminal.h index b1663d5..5ed6944 100644 --- a/agent/Terminal.h +++ b/agent/Terminal.h @@ -3,6 +3,7 @@ #include #include "Coord.h" +#include class NamedPipe; @@ -12,7 +13,7 @@ public: explicit Terminal(NamedPipe *output); void reset(bool sendClearFirst, int newLine); void sendLine(int line, CHAR_INFO *lineData, int width); - void finishOutput(const Coord &newCursorPos); + void finishOutput(const std::pair &newCursorPos); private: void hideTerminalCursor(); @@ -22,7 +23,7 @@ private: NamedPipe *m_output; int m_remoteLine; bool m_cursorHidden; - Coord m_cursorPos; + std::pair m_cursorPos; int m_remoteColor; };