[fpc-devel] Types.IntersectRect(), probably bug or misusage VERY URGENT

zeljko zeljko at holobit.net
Tue Oct 26 14:00:49 CEST 2010


Hi all,
Someone reported bug in gtk2lcl which crashes lazarus ide. I've found that 
intersectRect usage from types (from r 27870) makes that.
So imagine next code:
var
  R, SrcRect: TRect;
begin
   R := Rect(0, 0, 22, 22);
   SrcRect := Rect(0, 0, 24, 24);
   Types.IntersectRect(R, SrcRect, R);  
end;
In this case RETURNED value from intersectRect will be wrong R = 0, 0, 24, 24.
Now the question is: first param of Intersect is var, others are consts.

function IntersectRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
begin
  Rect:=R1; // <--------- WHAT IF Rect = R2 as in my example above ?
  with R2 do
    begin
    if Left>R1.Left then
      Rect.Left:=Left;
    if Top>R1.Top then
      Rect.Top:=Top;
    if Right<R1.Right then
      Rect.Right:=Right;
    if Bottom<R1.Bottom then
      Rect.Bottom:=Bottom;
    end;
  if IsRectEmpty(Rect) then
    begin
    FillChar(Rect,SizeOf(Rect),0);
    IntersectRect:=false;
    end
  else
    IntersectRect:=true;
end;

So MAIN question is:
1.My example shows misusage of IntersectRect
2.FPC Types.IntersectRect() have bug

thanks,
  zeljko



More information about the fpc-devel mailing list