From 498cd44c3a1845eb98cedf36f22775024ba79f0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 25 Nov 2005 16:20:32 +0000 Subject: [PATCH] Quick fix to prevent the terminal from crashing in case it got a message with mouse coordinates outside the window (yeah, it has been written that bad). Need to rewrite the whole mouse handling, though... git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15152 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/terminal/TermBuffer.cpp | 36 ++++++++++++++++++-------------- src/apps/terminal/TermView.cpp | 4 +++- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/apps/terminal/TermBuffer.cpp b/src/apps/terminal/TermBuffer.cpp index dd434062f4..45b35f7668 100644 --- a/src/apps/terminal/TermBuffer.cpp +++ b/src/apps/terminal/TermBuffer.cpp @@ -96,17 +96,18 @@ TermBuffer::TermBuffer(int rows, int cols) mRowSize = rows; mRowOffset = 0; - + //buffer_size = ARRAY_SIZE; buffer_size = gTermPref->getInt32 (PREF_HISTORY_SIZE); - + // Allocate buffer mBase = (term_buffer**) malloc (sizeof (term_buffer*) * buffer_size); - - for(int i = 0; i < buffer_size; i++) + + for (int i = 0; i < buffer_size; i++) mBase[i] = (term_buffer *) calloc (mColSize + 1, sizeof (term_buffer)); } + TermBuffer::~TermBuffer() { for(int i = 0; i < buffer_size; i++) @@ -115,26 +116,29 @@ TermBuffer::~TermBuffer() free(mBase); } -// Gets a character from TermBuffer + +//! Gets a character from TermBuffer int -TermBuffer::GetChar (int row, int col, uchar *buf, ushort *attr) +TermBuffer::GetChar(int row, int col, uchar *buf, ushort *attr) { - term_buffer *ptr; - - ptr = (mBase[row % buffer_size] + col); - + if (row < 0 || col < 0) + return -1; + + term_buffer *ptr = (mBase[row % buffer_size] + col); + if (ptr->status == A_CHAR) - memcpy (buf, (char *)(ptr->code), 4); - + memcpy(buf, (char *)(ptr->code), 4); + *attr = ptr->attr; - + return ptr->status; } -// Get a string (length = num) from given position. + +//! Get a string (length = num) from given position. int -TermBuffer::GetString (int row, int col, int num, uchar *buf, - ushort *attr) +TermBuffer::GetString(int row, int col, int num, uchar *buf, + ushort *attr) { int count = 0, all_count = 0; term_buffer *ptr; diff --git a/src/apps/terminal/TermView.cpp b/src/apps/terminal/TermView.cpp index cda23ba2d9..073866f6a1 100644 --- a/src/apps/terminal/TermView.cpp +++ b/src/apps/terminal/TermView.cpp @@ -904,7 +904,9 @@ TermView::MouseTracking(void *data) } edpos = theObj->BPointToCurPos(edpoint); - + if (edpos.y < 0) + continue; + if(stpoint == edpoint) { continue; } else {