From c8be7270680db7f4180ff47dfc09b118c3ca0e21 Mon Sep 17 00:00:00 2001 From: avolkov Date: Wed, 15 Aug 2007 06:20:42 +0000 Subject: [PATCH] Make SetEquFrameIndex safe git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2840 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/src/sc2code/libs/graphics/pixmap.c | 24 +++++++++++++++++------- sc2/src/sc2code/process.c | 9 +-------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/sc2/src/sc2code/libs/graphics/pixmap.c b/sc2/src/sc2code/libs/graphics/pixmap.c index 1b20138b7..e1e05adf8 100644 --- a/sc2/src/sc2code/libs/graphics/pixmap.c +++ b/sc2/src/sc2code/libs/graphics/pixmap.c @@ -17,6 +17,7 @@ */ #include "gfxintrn.h" +#include "libs/log.h" FRAME CaptureDrawable (DRAWABLE Drawable) @@ -128,14 +129,23 @@ SetRelFrameIndex (FRAME FramePtr, SIZE FrameOffs) FRAME SetEquFrameIndex (FRAME DstFramePtr, FRAME SrcFramePtr) { - if (DstFramePtr && SrcFramePtr) - return ((FRAME)( - (BYTE*)((GetFrameParentDrawable (DstFramePtr))->Frame) - + ((BYTE*)SrcFramePtr - - (BYTE*)((GetFrameParentDrawable (SrcFramePtr))->Frame)) - )); + COUNT Index; - return (0); + if (!DstFramePtr || !SrcFramePtr) + return 0; + + Index = GetFrameIndex (SrcFramePtr); +#ifdef DEBUG + { + DRAWABLE_DESC *DrawablePtr = GetFrameParentDrawable (DstFramePtr); + if (Index > DrawablePtr->MaxIndex) + log_add (log_Debug, "SetEquFrameIndex: source index (%d) beyond " + "destination range (%d)", (int)Index, + (int)DrawablePtr->MaxIndex); + } +#endif + + return SetAbsFrameIndex (DstFramePtr, Index); } FRAME diff --git a/sc2/src/sc2code/process.c b/sc2/src/sc2code/process.c index 4651e1f56..e216622c5 100644 --- a/sc2/src/sc2code/process.c +++ b/sc2/src/sc2code/process.c @@ -921,16 +921,9 @@ PostProcessQueue (VIEW_STATE view_state, SIZE scroll_x, else CALC_ZOOM_STUFF (&index, &scale); - ElementPtr->next.image.frame = -#ifdef SAFE - SetAbsFrameIndex ( - ElementPtr->next.image.farray[index], - GetFrameIndex (ElementPtr->next.image.frame)); -#else /* SAFE */ - SetEquFrameIndex ( + ElementPtr->next.image.frame = SetEquFrameIndex ( ElementPtr->next.image.farray[index], ElementPtr->next.image.frame); -#endif /* SAFE */ if (optMeleeScale == TFB_SCALE_TRILINEAR && index < 2 && scale != 256)