Branch: Tag:

2002-04-10

2002-04-10 21:27:10 by Stefan Wallström <stewa@roxen.com>

Fixed memory trashing when copying an area that is completely outside the image.

Rev: src/modules/Image/blit.c:1.50

1: - /* $Id: blit.c,v 1.49 2000/12/01 08:09:58 hubbe Exp $ */ + /* $Id: blit.c,v 1.50 2002/04/10 21:27:10 stewa Exp $ */   #include "global.h"      /*   **! module Image   **! note - **! $Id: blit.c,v 1.49 2000/12/01 08:09:58 hubbe Exp $ + **! $Id: blit.c,v 1.50 2002/04/10 21:27:10 stewa Exp $   **! class Image   */   
209:    INT32 x2,INT32 y2)   {    rgb_group *new; -  INT32 xp,yp,xs,ys; +  INT32 xp,yp,xs,ys,tmp;       if (dest->img) { free(dest->img); dest->img=NULL; }    -  if (x1>x2) x1^=x2,x2^=x1,x1^=x2; -  if (y1>y2) y1^=y2,y2^=y1,y1^=y2; +  if (x1>x2) tmp=x1, x1=x2, x2=tmp; +  if (y1>y2) tmp=y1, y1=y2, y2=tmp;       if (x1==0 && y1==0 &&    img->xsize-1==x2 && img->ysize-1==y2)
244:    xs=MAXIMUM(0,x1);    ys=MAXIMUM(0,y1);    +  if( ! (( x2 < 0) || (y2 < 0) || (x1>=img->xsize) || (y1>=img->ysize))) { +     if (x1<0) x1=0; else if (x1>=img->xsize) x1=img->xsize-1;    if (y1<0) y1=0; else if (y1>=img->ysize) y1=img->ysize-1;    if (x2<0) x2=0; else if (x2>=img->xsize) x2=img->xsize-1;
256:    dest->xsize,    img->xsize);    +  }    dest->img=new;   }