From 06a978b8e3c0702b853069e627db41c51b3b11fd Mon Sep 17 00:00:00 2001 From: zeljko Date: Mon, 30 Nov 2009 20:43:38 +0000 Subject: [PATCH] Qt: fix segfault when creating QRegion with negative width or height.Fixed implementation of GetRgnBox, so it doesn't ask for QRegion_boundingRect() if returned region type is ERROR or NULLREGION. git-svn-id: trunk@22881 - --- lcl/interfaces/qt/qtobjects.pas | 15 +++++++++++++-- lcl/interfaces/qt/qtwinapi.inc | 9 ++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lcl/interfaces/qt/qtobjects.pas b/lcl/interfaces/qt/qtobjects.pas index 43466045a3..4fcf84b9e8 100644 --- a/lcl/interfaces/qt/qtobjects.pas +++ b/lcl/interfaces/qt/qtobjects.pas @@ -1631,7 +1631,7 @@ begin {$endif} // Creates the widget - if CreateHandle then Widget := QRegion_create; + if CreateHandle then Widget := QRegion_create(); end; {------------------------------------------------------------------------------ @@ -1641,6 +1641,8 @@ end; ------------------------------------------------------------------------------} constructor TQtRegion.Create(CreateHandle: Boolean; X1,Y1,X2,Y2:Integer; Const RegionType: QRegionRegionType = QRegionRectangle); +var + W, H: Integer; begin {$ifdef VerboseQt} WriteLn('TQtRegion.Create CreateHandle: ', dbgs(CreateHandle)); @@ -1649,7 +1651,16 @@ begin // Creates the widget // Note that QRegion_create expects a width and a height, // and not a X2, Y2 bottom-right point - if CreateHandle then Widget := QRegion_create(X1,Y1,X2-X1,Y2-Y1, RegionType); + if CreateHandle then + begin + W := X2 - X1; + H := Y2 - Y1; + if W < 0 then + W := 0; + if H < 0 then + H := 0; + Widget := QRegion_create(X1, Y1, W, H, RegionType); + end; end; constructor TQtRegion.Create(CreateHandle: Boolean; Poly: QPolygonH; diff --git a/lcl/interfaces/qt/qtwinapi.inc b/lcl/interfaces/qt/qtwinapi.inc index b3b9990711..59e7668cb5 100644 --- a/lcl/interfaces/qt/qtwinapi.inc +++ b/lcl/interfaces/qt/qtwinapi.inc @@ -2581,20 +2581,19 @@ var R: TRect; begin {$ifdef VerboseQtWinAPI} - WriteLn('[WinAPI TQtWidgetSet.GetRgnBox] possible wrong implementation !'); + writeln('Trace:> [WinAPI GetRgnBox] Handle: ' + dbghex(RGN)); {$endif} Result := SIMPLEREGION; - If lpRect <> nil then + if lpRect <> nil then lpRect^ := Rect(0,0,0,0); - If Not IsValidGDIObject(RGN) then + if not IsValidGDIObject(RGN) then Result := ERROR else begin Result := TQtRegion(RGN).GetRegionType; - If lpRect <> nil then + if not (Result in [ERROR, NULLREGION]) and (lpRect <> nil) then begin QRegion_boundingRect(TQtRegion(RGN).Widget, @R); - with lpRect^ do begin Left := R.Left;