Convert loc() to function and add arguments checks

Summary:
For debug builds, the function will fail when called with out of display
coordinates, allowing to spot addressing errors. For regular builds,
it will limit coordinates to valid area without triggering errors.

Depends on D12551

Test Plan: * Compiles, does not fail with use cases from previous commit

Reviewers: #konsole, hindenburg

Reviewed By: #konsole, hindenburg

Subscribers: konsole-devel, hindenburg, #konsole

Tags: #konsole

Differential Revision: https://phabricator.kde.org/D12553
wilder-portage
Mariusz Glebocki 8 years ago committed by Kurt Hindenburg
parent 39aebeafea
commit 674de973f9
  1. 13
      src/TerminalDisplay.cpp
  2. 2
      src/TerminalDisplay.h

@ -74,10 +74,6 @@
using namespace Konsole;
#ifndef loc
#define loc(X,Y) ((Y)*_columns+(X))
#endif
#define REPCHAR "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
"abcdefgjijklmnopqrstuvwxyz" \
"0123456789./+@"
@ -86,6 +82,15 @@ using namespace Konsole;
// more information can be found in: http://unicode.org/reports/tr9/
const QChar LTR_OVERRIDE_CHAR(0x202D);
inline int TerminalDisplay::loc(int x, int y) const {
Q_ASSERT(y >= 0 && y < _lines);
Q_ASSERT(x >= 0 && x < _columns);
x = qBound(0, x, _columns - 1);
y = qBound(0, y, _lines - 1);
return y * _columns + x;
}
/* ------------------------------------------------------------------------- */
/* */
/* Colors */

@ -915,6 +915,8 @@ private:
// Boilerplate setup for MessageWidget
KMessageWidget* createMessageWidget(const QString &text);
int loc(int x, int y) const;
// the window onto the terminal screen which this display
// is currently showing.
QPointer<ScreenWindow> _screenWindow;

Loading…
Cancel
Save