From ffd3bf50e59db2bb53df757a4d648ba42c6cafc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Czerpak?= Date: Thu, 28 Jan 2016 13:00:23 +0100 Subject: [PATCH] 2016-01-28 13:00 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * src/rtl/gtxwc/gtxwc.c ! fixed buffer overflow in HB_GTI_FONTATTRIBUTE used after after console window initialization ! set XLib mutex when font size is changed by HB_GTI_FONTSIZE after console window initialization (for MT programs using more then one GTXWC console simultaneously). ! allow HB_GTI_FONTSIZE to change font created by HB_GTI_FONTSEL using before console window is created % do not create new console window pixmap if old one has the same dimensions --- ChangeLog.txt | 12 +++++++ src/rtl/gtxwc/gtxwc.c | 83 ++++++++++++++++++++++++++----------------- 2 files changed, 63 insertions(+), 32 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index c4bc8018bf..1e66260ee8 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,18 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2016-01-28 13:00 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * src/rtl/gtxwc/gtxwc.c + ! fixed buffer overflow in HB_GTI_FONTATTRIBUTE used after + after console window initialization + ! set XLib mutex when font size is changed by HB_GTI_FONTSIZE + after console window initialization (for MT programs using + more then one GTXWC console simultaneously). + ! allow HB_GTI_FONTSIZE to change font created by HB_GTI_FONTSEL + using before console window is created + % do not create new console window pixmap if old one has the + same dimensions + 2016-01-26 15:44 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * include/hbapierr.h * include/hbdefs.h diff --git a/src/rtl/gtxwc/gtxwc.c b/src/rtl/gtxwc/gtxwc.c index 49569c3662..e4867870e4 100644 --- a/src/rtl/gtxwc/gtxwc.c +++ b/src/rtl/gtxwc/gtxwc.c @@ -3939,7 +3939,17 @@ static void hb_gt_xwc_InvalidateChar( PXWND_DEF wnd, wnd->fInvalidChr = HB_TRUE; } -static void hb_gt_xwc_InvalidateFull( PXWND_DEF wnd, +static void hb_gt_xwc_InvalidateFull( PXWND_DEF wnd ) +{ + HB_SIZE nSize = wnd->cols * wnd->rows; + + while( nSize-- ) + wnd->pCurrScr[ nSize ] = 0xFFFFFFFF; + + hb_gt_xwc_InvalidateChar( wnd, 0, 0, wnd->cols - 1, wnd->rows - 1 ); +} + +static void hb_gt_xwc_InvalidatePart( PXWND_DEF wnd, int left, int top, int right, int bottom ) { int row, col, scridx; @@ -4112,19 +4122,18 @@ static HB_BOOL hb_gt_xwc_SetScrBuff( PXWND_DEF wnd, HB_USHORT cols, HB_USHORT ro if( rows <= XWC_MAX_ROWS && cols <= XWC_MAX_COLS && ( wnd->cols != cols || wnd->rows != rows || wnd->pCurrScr == NULL ) ) { - HB_SIZE nSize = cols * rows; + if( HB_GTSELF_RESIZE( wnd->pGT, rows, cols ) ) + { + wnd->cols = cols; + wnd->rows = rows; - wnd->cols = cols; - wnd->rows = rows; + if( wnd->pCurrScr != NULL ) + hb_xfree( wnd->pCurrScr ); + wnd->pCurrScr = ( HB_U32 * ) hb_xgrab( cols * rows * sizeof( HB_U32 ) ); + hb_gt_xwc_InvalidateFull( wnd ); - if( wnd->pCurrScr != NULL ) - hb_xfree( wnd->pCurrScr ); - wnd->pCurrScr = ( HB_U32 * ) hb_xgrab( nSize * sizeof( HB_U32 ) ); - memset( wnd->pCurrScr, 0xFF, nSize * sizeof( HB_U32 ) ); - - hb_gt_xwc_InvalidateChar( wnd, 0, 0, wnd->cols - 1, wnd->rows - 1 ); - - return HB_GTSELF_RESIZE( wnd->pGT, wnd->rows, wnd->cols ); + return HB_TRUE; + } } return HB_FALSE; @@ -4139,14 +4148,19 @@ static void hb_gt_xwc_CreatePixmap( PXWND_DEF wnd ) width = wnd->cols * wnd->fontWidth; height = wnd->rows * wnd->fontHeight; - if( wnd->pm ) - XFreePixmap( wnd->dpy, wnd->pm ); + if( ! wnd->pm || wnd->width != width || wnd->height != height ) + { + if( wnd->pm ) + XFreePixmap( wnd->dpy, wnd->pm ); - wnd->pm = XCreatePixmap( wnd->dpy, wnd->window, width, height, - DefaultDepth( wnd->dpy, DefaultScreen( wnd->dpy ) ) ); - wnd->drw = wnd->pm; - wnd->width = width; - wnd->height = height; + wnd->pm = XCreatePixmap( wnd->dpy, wnd->window, width, height, + DefaultDepth( wnd->dpy, DefaultScreen( wnd->dpy ) ) ); + wnd->drw = wnd->pm; + wnd->width = width; + wnd->height = height; + + hb_gt_xwc_InvalidateFull( wnd ); + } } /* *********************************************************************** */ @@ -5258,9 +5272,20 @@ static HB_BOOL hb_gt_xwc_Info( PHB_GT pGT, int iType, PHB_GT_INFO pInfo ) wnd->fontHeight = iVal; if( wnd->fInit ) { - hb_gt_xwc_SetFont( wnd, wnd->szFontName, wnd->fontWeight, - wnd->fontHeight, wnd->szFontEncoding ); - hb_gt_xwc_CreateWindow( wnd ); + HB_BOOL fInit; + HB_XWC_XLIB_LOCK(); + fInit = hb_gt_xwc_SetFont( wnd, wnd->szFontName, wnd->fontWeight, + wnd->fontHeight, wnd->szFontEncoding ); + HB_XWC_XLIB_UNLOCK(); + if( fInit ) + hb_gt_xwc_CreateWindow( wnd ); + } + else if( wnd->xfs ) + { + HB_XWC_XLIB_LOCK(); + XFreeFont( wnd->dpy, wnd->xfs ); + wnd->xfs = NULL; + HB_XWC_XLIB_UNLOCK(); } } break; @@ -5326,8 +5351,8 @@ static HB_BOOL hb_gt_xwc_Info( PHB_GT pGT, int iType, PHB_GT_INFO pInfo ) { HB_XWC_XLIB_LOCK(); hb_gt_xwc_ResetCharTrans( wnd ); - hb_gt_xwc_InvalidateFull( wnd, 0, 0, wnd->cols - 1, wnd->rows ); HB_XWC_XLIB_UNLOCK(); + hb_gt_xwc_InvalidateFull( wnd ); } } break; @@ -5664,10 +5689,7 @@ static HB_BOOL hb_gt_xwc_Info( PHB_GT pGT, int iType, PHB_GT_INFO pInfo ) { HB_XWC_XLIB_LOCK(); if( hb_gt_xwc_setPalette( wnd ) ) - { - memset( wnd->pCurrScr, 0xFF, wnd->cols * wnd->rows * sizeof( HB_U32 ) ); - hb_gt_xwc_InvalidateChar( wnd, 0, 0, wnd->cols - 1, wnd->rows - 1 ); - } + hb_gt_xwc_InvalidateFull( wnd ); HB_XWC_XLIB_UNLOCK(); } } @@ -5697,10 +5719,7 @@ static HB_BOOL hb_gt_xwc_Info( PHB_GT pGT, int iType, PHB_GT_INFO pInfo ) { HB_XWC_XLIB_LOCK(); if( hb_gt_xwc_setPalette( wnd ) ) - { - memset( wnd->pCurrScr, 0xFF, wnd->cols * wnd->rows * sizeof( HB_U32 ) ); - hb_gt_xwc_InvalidateChar( wnd, 0, 0, wnd->cols - 1, wnd->rows - 1 ); - } + hb_gt_xwc_InvalidateFull( wnd ); HB_XWC_XLIB_UNLOCK(); } } @@ -5813,7 +5832,7 @@ static HB_BOOL hb_gt_xwc_Info( PHB_GT pGT, int iType, PHB_GT_INFO pInfo ) hb_gt_xwc_InvalidatePts( wnd, rx.left, rx.top, rx.right, rx.bottom ); } else - hb_gt_xwc_InvalidateFull( wnd, rx.left / wnd->fontWidth, + hb_gt_xwc_InvalidatePart( wnd, rx.left / wnd->fontWidth, rx.top / wnd->fontHeight, rx.right / wnd->fontWidth, rx.bottom / wnd->fontHeight );