diff --git a/Source/v_video.c b/Source/v_video.c index 31b6e4cf..a500744e 100644 --- a/Source/v_video.c +++ b/Source/v_video.c @@ -296,7 +296,7 @@ void V_DrawPatchGeneral(int x, int y, int scrn, patch_t *patch, y -= SHORT(patch->topoffset); x -= SHORT(patch->leftoffset); -#ifdef RANGECHECK +#ifdef RANGECHECK_NOTHANKS if (x<0 ||x+SHORT(patch->width) >SCREENWIDTH || y<0 @@ -312,11 +312,21 @@ void V_DrawPatchGeneral(int x, int y, int scrn, patch_t *patch, { byte *desttop = screens[scrn]+y*SCREENWIDTH*4+x*2; - for ( ; col != colstop ; col += colstep, desttop+=2) + for ( ; col != colstop ; col += colstep, desttop+=2, x++) { 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) { @@ -326,6 +336,20 @@ void V_DrawPatchGeneral(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--, source++, dest += SCREENWIDTH*4, topy++; + // [FG] too low, too tall + while (topy + count > SCREENHEIGHT) + count--; + // [FG] nothing left to draw? + if (count < 1) + break; + } + if ((count-=4)>=0) do { @@ -371,11 +395,21 @@ void V_DrawPatchGeneral(int x, int y, int scrn, patch_t *patch, { byte *desttop = screens[scrn]+y*SCREENWIDTH+x; - for ( ; col != colstop ; col += colstep, desttop++) + for ( ; col != colstop ; col += colstep, desttop++, x++) { 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) { @@ -385,6 +419,20 @@ void V_DrawPatchGeneral(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--, source++, dest += SCREENWIDTH, topy++; + // [FG] too low, too tall + while (topy + count > SCREENHEIGHT) + count--; + // [FG] nothing left to draw? + if (count < 1) + break; + } + if ((count-=4)>=0) do {