bring implementation of V_DrawPatchTranslated into line with V_DrawPatchGeneral (#519)

* bring implementation of V_DrawPatchTranslated into line with V_DrawPatchGeneral

* add missed overflow checks
This commit is contained in:
Roman Fomin 2022-04-25 16:21:19 +07:00 committed by GitHub
parent a53db1906c
commit ad6684b7c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -553,7 +553,7 @@ void V_DrawPatchTranslated(int x, int y, int scrn, patch_t *patch,
x += WIDESCREENDELTA; // [crispy] horizontal widescreen offset
#ifdef RANGECHECK
#ifdef RANGECHECK_NOTHANKS
if (x<0
||x+SHORT(patch->width) >SCREENWIDTH
|| y<0
@ -577,6 +577,16 @@ void V_DrawPatchTranslated(int x, int y, int scrn, patch_t *patch,
const column_t *column =
(const column_t *)((byte *)patch + LONG(patch->columnofs[col]));
// [FG] prevent framebuffer overflows
{
// [FG] too far left
if (x < 0)
continue;
// [FG] too far right, too wide
if (x >= SCREENWIDTH)
break;
}
// step through the posts in a column
while (column->topdelta != 0xff)
{
@ -586,6 +596,17 @@ void V_DrawPatchTranslated(int x, int y, int scrn, patch_t *patch,
register byte *dest = desttop + column->topdelta*SCREENWIDTH*4;
register int count = column->length;
// [FG] prevent framebuffer overflows
{
int topy = y + column->topdelta;
// [FG] too high
while (topy < 0 && count)
count--, source++, dest += SCREENWIDTH*4, topy++;
// [FG] too low, too tall
while (topy + count > SCREENHEIGHT && count)
count--;
}
if ((count-=4)>=0)
do
{
@ -627,7 +648,9 @@ void V_DrawPatchTranslated(int x, int y, int scrn, patch_t *patch,
dest += SCREENWIDTH*4;
}
while (--count);
column = (column_t *)(source+1);
// column = (column_t *)(source+1);
// [FG] back to Vanilla code, we may not run through the entire column
column = (column_t *)((byte *)column + column->length + 4);
}
}
}
@ -640,6 +663,16 @@ void V_DrawPatchTranslated(int x, int y, int scrn, patch_t *patch,
const column_t *column =
(const column_t *)((byte *)patch + LONG(patch->columnofs[col]));
// [FG] prevent framebuffer overflows
{
// [FG] too far left
if (x < 0)
continue;
// [FG] too far right, too wide
if (x >= SCREENWIDTH)
break;
}
// step through the posts in a column
while (column->topdelta != 0xff)
{
@ -649,6 +682,17 @@ void V_DrawPatchTranslated(int x, int y, int scrn, patch_t *patch,
register byte *dest = desttop + column->topdelta*SCREENWIDTH;
register int count = column->length;
// [FG] prevent framebuffer overflows
{
int topy = y + column->topdelta;
// [FG] too high
while (topy < 0 && count)
count--, source++, dest += SCREENWIDTH, topy++;
// [FG] too low, too tall
while (topy + count > SCREENHEIGHT && count)
count--;
}
if ((count-=4)>=0)
do
{
@ -681,7 +725,9 @@ void V_DrawPatchTranslated(int x, int y, int scrn, patch_t *patch,
dest += SCREENWIDTH;
}
while (--count);
column = (column_t *)(source+1);
// column = (column_t *)(source+1);
// [FG] back to Vanilla code, we may not run through the entire column
column = (column_t *)((byte *)column + column->length + 4);
}
}