Recoded the DRAWABLE_DESC datatype so that it no longer relies on
"intentional buffer overflows". git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@942 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
Changes towards version 0.3:
|
Changes towards version 0.3:
|
||||||
|
- The DRAWABLE_DESC datatype now uses separately allocated arrays for
|
||||||
|
animation frames instead of doing pointer arithmetic between it and
|
||||||
|
FRAME_DESCs --McMartin
|
||||||
- Date on the green bar now has floating period between day and
|
- Date on the green bar now has floating period between day and
|
||||||
the year like in PC version (bug #307 part 5) -Mika
|
the year like in PC version (bug #307 part 5) -Mika
|
||||||
- AWARE_OF_SAMATRA flag is now written as well as read (closes #113),
|
- AWARE_OF_SAMATRA flag is now written as well as read (closes #113),
|
||||||
|
|||||||
@@ -256,7 +256,6 @@ extern DRAWABLE CreateDisplay (CREATE_FLAGS CreateFlags, PSIZE pwidth,
|
|||||||
PSIZE pheight);
|
PSIZE pheight);
|
||||||
extern DRAWABLE CreateDrawable (CREATE_FLAGS CreateFlags, SIZE width,
|
extern DRAWABLE CreateDrawable (CREATE_FLAGS CreateFlags, SIZE width,
|
||||||
SIZE height, COUNT num_frames);
|
SIZE height, COUNT num_frames);
|
||||||
extern DRAWABLE CopyDrawable (DRAWABLE Drawable);
|
|
||||||
extern BOOLEAN DestroyDrawable (DRAWABLE Drawable);
|
extern BOOLEAN DestroyDrawable (DRAWABLE Drawable);
|
||||||
extern BOOLEAN GetFrameRect (FRAME Frame, PRECT pRect);
|
extern BOOLEAN GetFrameRect (FRAME Frame, PRECT pRect);
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "gfxintrn.h"
|
#include "gfxintrn.h"
|
||||||
|
#include "misc.h"
|
||||||
|
|
||||||
FRAMEPTR _CurFramePtr;
|
FRAMEPTR _CurFramePtr;
|
||||||
|
|
||||||
@@ -77,6 +78,36 @@ CreateDisplay (CREATE_FLAGS CreateFlags, PSIZE pwidth, PSIZE pheight)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DRAWABLE
|
||||||
|
AllocDrawable (COUNT n)
|
||||||
|
{
|
||||||
|
DRAWABLE Drawable;
|
||||||
|
Drawable = (DRAWABLE)mem_allocate ((MEM_SIZE)(sizeof (DRAWABLE_DESC)),
|
||||||
|
MEM_ZEROINIT | MEM_GRAPHICS,
|
||||||
|
DRAWABLE_PRIORITY, MEM_SIMPLE);
|
||||||
|
if (Drawable)
|
||||||
|
{
|
||||||
|
DRAWABLEPTR DrawablePtr;
|
||||||
|
int i;
|
||||||
|
DrawablePtr = LockDrawable (Drawable);
|
||||||
|
DrawablePtr->Frame = (FRAMEPTR)HMalloc ((MEM_SIZE)(sizeof (FRAME_DESC) * n));
|
||||||
|
|
||||||
|
/* Zero out the newly allocated frames, since HMalloc doesn't have MEM_ZEROINIT. */
|
||||||
|
for (i = 0; i < n; i++) {
|
||||||
|
FRAMEPTR F;
|
||||||
|
F = &DrawablePtr->Frame[i];
|
||||||
|
F->parent = DrawablePtr;
|
||||||
|
F->TypeIndexAndFlags = 0;
|
||||||
|
F->image = 0;
|
||||||
|
F->Bounds = 0;
|
||||||
|
F->HotSpot.x = F->HotSpot.y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
UnlockDrawable (Drawable);
|
||||||
|
}
|
||||||
|
return Drawable;
|
||||||
|
}
|
||||||
|
|
||||||
DRAWABLE
|
DRAWABLE
|
||||||
CreateDrawable (CREATE_FLAGS CreateFlags, SIZE width, SIZE height, COUNT
|
CreateDrawable (CREATE_FLAGS CreateFlags, SIZE width, SIZE height, COUNT
|
||||||
num_frames)
|
num_frames)
|
||||||
@@ -107,58 +138,6 @@ CreateDrawable (CREATE_FLAGS CreateFlags, SIZE width, SIZE height, COUNT
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
DRAWABLE
|
|
||||||
CopyDrawable (DRAWABLE Drawable)
|
|
||||||
{
|
|
||||||
DRAWABLEPTR DrawablePtr;
|
|
||||||
|
|
||||||
DrawablePtr = LockDrawable (Drawable);
|
|
||||||
if (DrawablePtr)
|
|
||||||
{
|
|
||||||
DRAWABLE CopyDrawable;
|
|
||||||
DWORD size;
|
|
||||||
|
|
||||||
if (TYPE_GET (DrawablePtr->Frame[0].TypeIndexAndFlags) == SCREEN_DRAWABLE)
|
|
||||||
CopyDrawable = 0;
|
|
||||||
else if ((CopyDrawable = AllocDrawable (1,
|
|
||||||
(size = mem_get_size ((MEM_HANDLE)Drawable))
|
|
||||||
- sizeof (DRAWABLE_DESC))))
|
|
||||||
{
|
|
||||||
DRAWABLEPTR CopyDrawablePtr;
|
|
||||||
|
|
||||||
if ((CopyDrawablePtr = LockDrawable (CopyDrawable)) == 0)
|
|
||||||
{
|
|
||||||
FreeDrawable (CopyDrawable);
|
|
||||||
CopyDrawable = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
PBYTE lpDst, lpSrc;
|
|
||||||
|
|
||||||
lpDst = (PBYTE)CopyDrawablePtr;
|
|
||||||
lpSrc = (PBYTE)DrawablePtr;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
COUNT num_bytes;
|
|
||||||
|
|
||||||
num_bytes = size >= 0x7FFF ? 0x7FFF : (COUNT)size;
|
|
||||||
memcpy (lpDst, lpSrc, num_bytes);
|
|
||||||
lpDst += num_bytes;
|
|
||||||
lpSrc += num_bytes;
|
|
||||||
size -= num_bytes;
|
|
||||||
} while (size);
|
|
||||||
CopyDrawablePtr->hDrawable = (MEM_HANDLE)CopyDrawable;
|
|
||||||
UnlockDrawable (CopyDrawable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
UnlockDrawable (Drawable);
|
|
||||||
|
|
||||||
return (CopyDrawable);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
DestroyDrawable (DRAWABLE Drawable)
|
DestroyDrawable (DRAWABLE Drawable)
|
||||||
{
|
{
|
||||||
@@ -170,6 +149,7 @@ DestroyDrawable (DRAWABLE Drawable)
|
|||||||
DrawablePtr = LockDrawable (Drawable);
|
DrawablePtr = LockDrawable (Drawable);
|
||||||
if (DrawablePtr)
|
if (DrawablePtr)
|
||||||
{
|
{
|
||||||
|
HFree (DrawablePtr->Frame);
|
||||||
UnlockDrawable (Drawable);
|
UnlockDrawable (Drawable);
|
||||||
FreeDrawable (Drawable);
|
FreeDrawable (Drawable);
|
||||||
|
|
||||||
|
|||||||
@@ -69,15 +69,16 @@ typedef struct
|
|||||||
HOT_SPOT HotSpot;
|
HOT_SPOT HotSpot;
|
||||||
DWORD Bounds;
|
DWORD Bounds;
|
||||||
TFB_Image *image;
|
TFB_Image *image;
|
||||||
|
struct _drawable_desc *parent;
|
||||||
} FRAME_DESC;
|
} FRAME_DESC;
|
||||||
typedef FRAME_DESC *PFRAME_DESC;
|
typedef FRAME_DESC *PFRAME_DESC;
|
||||||
|
|
||||||
typedef struct
|
typedef struct _drawable_desc
|
||||||
{
|
{
|
||||||
MEM_HANDLE hDrawable;
|
MEM_HANDLE hDrawable;
|
||||||
|
|
||||||
UWORD FlagsAndIndex;
|
UWORD FlagsAndIndex;
|
||||||
FRAME_DESC Frame[1];
|
FRAME_DESC *Frame;
|
||||||
} DRAWABLE_DESC;
|
} DRAWABLE_DESC;
|
||||||
typedef DRAWABLE_DESC *PDRAWABLE_DESC;
|
typedef DRAWABLE_DESC *PDRAWABLE_DESC;
|
||||||
|
|
||||||
@@ -94,19 +95,13 @@ typedef DRAWABLE_DESC *PDRAWABLE_DESC;
|
|||||||
#define FRAMEPTR PFRAME_DESC
|
#define FRAMEPTR PFRAME_DESC
|
||||||
#define COUNTPTR PCOUNT
|
#define COUNTPTR PCOUNT
|
||||||
|
|
||||||
#define AllocDrawable(n,dc) \
|
extern DRAWABLE AllocDrawable (COUNT num_frames);
|
||||||
(DRAWABLE)mem_allocate ((MEM_SIZE)(sizeof (DRAWABLE_DESC) \
|
|
||||||
+ (sizeof (FRAME_DESC) * ((n) - 1))) + (dc), \
|
|
||||||
MEM_ZEROINIT | MEM_GRAPHICS, \
|
|
||||||
DRAWABLE_PRIORITY, MEM_SIMPLE)
|
|
||||||
#define LockDrawable(D) ((DRAWABLEPTR)mem_lock (GetDrawableHandle (D)))
|
#define LockDrawable(D) ((DRAWABLEPTR)mem_lock (GetDrawableHandle (D)))
|
||||||
#define UnlockDrawable(D) mem_unlock (GetDrawableHandle (D))
|
#define UnlockDrawable(D) mem_unlock (GetDrawableHandle (D))
|
||||||
#define FreeDrawable(D) _ReleaseCelData (GetDrawableHandle (D))
|
#define FreeDrawable(D) _ReleaseCelData (GetDrawableHandle (D))
|
||||||
#define GetDrawableHandle(D) ((MEM_HANDLE)LOWORD (D))
|
#define GetDrawableHandle(D) ((MEM_HANDLE)LOWORD (D))
|
||||||
#define GetDrawableIndex(D) ((COUNT)HIWORD (D))
|
#define GetDrawableIndex(D) ((COUNT)HIWORD (D))
|
||||||
#define GetFrameParentDrawable(F) ((DRAWABLEPTR)((PBYTE)((F) \
|
#define GetFrameParentDrawable(F) (F)->parent
|
||||||
-((int)INDEX_GET((F)->TypeIndexAndFlags)-1)) \
|
|
||||||
-sizeof(DRAWABLE_DESC)))
|
|
||||||
|
|
||||||
#define NULL_DRAWABLE (DRAWABLE)NULL_PTR
|
#define NULL_DRAWABLE (DRAWABLE)NULL_PTR
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ alloc_image (COUNT NumFrames, DRAWABLE_TYPE DrawableType, CREATE_FLAGS
|
|||||||
(void)flags;
|
(void)flags;
|
||||||
(void)width;
|
(void)width;
|
||||||
(void)height;
|
(void)height;
|
||||||
return AllocDrawable (NumFrames, 0);
|
return AllocDrawable (NumFrames);
|
||||||
}
|
}
|
||||||
|
|
||||||
static DISPLAY_INTERFACE DisplayInterface =
|
static DISPLAY_INTERFACE DisplayInterface =
|
||||||
|
|||||||
@@ -461,7 +461,7 @@ _GetCelData (FILE *fp, DWORD length)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
Drawable = 0;
|
Drawable = 0;
|
||||||
if (cel_ct && (Drawable = AllocDrawable (cel_ct, 0)))
|
if (cel_ct && (Drawable = AllocDrawable (cel_ct)))
|
||||||
{
|
{
|
||||||
DRAWABLEPTR DrawablePtr;
|
DRAWABLEPTR DrawablePtr;
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ TFB_Prim_Point (PPOINT p, TFB_Palette *color)
|
|||||||
r.corner.y = p->y - _CurFramePtr->HotSpot.y;
|
r.corner.y = p->y - _CurFramePtr->HotSpot.y;
|
||||||
r.extent.width = r.extent.height = 1;
|
r.extent.width = r.extent.height = 1;
|
||||||
|
|
||||||
if (TYPE_GET (_CurFramePtr->TypeIndexAndFlags) == SCREEN_DRAWABLE)
|
if (TYPE_GET (_CurFramePtr->TypeIndexAndFlags) & SCREEN_DRAWABLE)
|
||||||
TFB_DrawScreen_Rect (&r, color->r, color->g, color->b, TFB_SCREEN_MAIN);
|
TFB_DrawScreen_Rect (&r, color->r, color->g, color->b, TFB_SCREEN_MAIN);
|
||||||
else
|
else
|
||||||
TFB_DrawImage_Rect (&r, color->r, color->g, color->b, _CurFramePtr->image);
|
TFB_DrawImage_Rect (&r, color->r, color->g, color->b, _CurFramePtr->image);
|
||||||
@@ -86,7 +86,7 @@ TFB_Prim_FillRect (PRECT r, TFB_Palette *color)
|
|||||||
rect.extent.height) >> 1;
|
rect.extent.height) >> 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TYPE_GET (_CurFramePtr->TypeIndexAndFlags) == SCREEN_DRAWABLE)
|
if (TYPE_GET (_CurFramePtr->TypeIndexAndFlags) & SCREEN_DRAWABLE)
|
||||||
TFB_DrawScreen_Rect (&rect, color->r, color->g, color->b, TFB_SCREEN_MAIN);
|
TFB_DrawScreen_Rect (&rect, color->r, color->g, color->b, TFB_SCREEN_MAIN);
|
||||||
else
|
else
|
||||||
TFB_DrawImage_Rect (&rect, color->r, color->g, color->b, _CurFramePtr->image);
|
TFB_DrawImage_Rect (&rect, color->r, color->g, color->b, _CurFramePtr->image);
|
||||||
@@ -102,7 +102,7 @@ TFB_Prim_Line (PLINE line, TFB_Palette *color)
|
|||||||
x2=line->second.x - _CurFramePtr->HotSpot.x;
|
x2=line->second.x - _CurFramePtr->HotSpot.x;
|
||||||
y2=line->second.y - _CurFramePtr->HotSpot.y;
|
y2=line->second.y - _CurFramePtr->HotSpot.y;
|
||||||
|
|
||||||
if (TYPE_GET (_CurFramePtr->TypeIndexAndFlags) == SCREEN_DRAWABLE)
|
if (TYPE_GET (_CurFramePtr->TypeIndexAndFlags) & SCREEN_DRAWABLE)
|
||||||
TFB_DrawScreen_Line (x1, y1, x2, y2, color->r, color->g, color->b, TFB_SCREEN_MAIN);
|
TFB_DrawScreen_Line (x1, y1, x2, y2, color->r, color->g, color->b, TFB_SCREEN_MAIN);
|
||||||
else
|
else
|
||||||
TFB_DrawImage_Line (x1, y1, x2, y2, color->r, color->g, color->b, _CurFramePtr->image);
|
TFB_DrawImage_Line (x1, y1, x2, y2, color->r, color->g, color->b, _CurFramePtr->image);
|
||||||
@@ -155,7 +155,7 @@ TFB_Prim_Stamp (PSTAMP stmp)
|
|||||||
|
|
||||||
UnlockMutex (img->mutex);
|
UnlockMutex (img->mutex);
|
||||||
|
|
||||||
if (TYPE_GET (_CurFramePtr->TypeIndexAndFlags) == SCREEN_DRAWABLE)
|
if (TYPE_GET (_CurFramePtr->TypeIndexAndFlags) & SCREEN_DRAWABLE)
|
||||||
{
|
{
|
||||||
TFB_DrawScreen_Image (img, x, y, gscale, (paletted ? palette : NULL),
|
TFB_DrawScreen_Image (img, x, y, gscale, (paletted ? palette : NULL),
|
||||||
TFB_SCREEN_MAIN);
|
TFB_SCREEN_MAIN);
|
||||||
@@ -209,7 +209,7 @@ TFB_Prim_StampFill (PSTAMP stmp, TFB_Palette *color)
|
|||||||
|
|
||||||
UnlockMutex (img->mutex);
|
UnlockMutex (img->mutex);
|
||||||
|
|
||||||
if (TYPE_GET (_CurFramePtr->TypeIndexAndFlags) == SCREEN_DRAWABLE)
|
if (TYPE_GET (_CurFramePtr->TypeIndexAndFlags) & SCREEN_DRAWABLE)
|
||||||
{
|
{
|
||||||
TFB_DrawScreen_FilledImage (img, x, y, gscale, r, g, b,
|
TFB_DrawScreen_FilledImage (img, x, y, gscale, r, g, b,
|
||||||
TFB_SCREEN_MAIN);
|
TFB_SCREEN_MAIN);
|
||||||
|
|||||||
Reference in New Issue
Block a user