Skip to content

Commit

Permalink
GRAPHICS: fix off-by-one errors when drawing a rounded rectangle
Browse files Browse the repository at this point in the history
The code would create a rectangle of width+1 by weight+1, resulting
in buffer overflows when drawing at the bottom limit of a surface.
  • Loading branch information
benoit-pierre authored and sev- committed Nov 21, 2021
1 parent 6ba2fb9 commit 2d8e057
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions graphics/VectorRendererSpec.cpp
Expand Up @@ -4140,9 +4140,9 @@ drawInteriorRoundedSquareAlg(int x1, int y1, int r, int w, int h, PixelType colo
rsq = r*r;

PixelType *ptr_tl = (PixelType *)Base::_activeSurface->getBasePtr(x1 + r, y1 + r);
PixelType *ptr_tr = (PixelType *)Base::_activeSurface->getBasePtr(x1 + w - r, y1 + r);
PixelType *ptr_bl = (PixelType *)Base::_activeSurface->getBasePtr(x1 + r, y1 + h - r);
PixelType *ptr_br = (PixelType *)Base::_activeSurface->getBasePtr(x1 + w - r, y1 + h - r);
PixelType *ptr_tr = (PixelType *)Base::_activeSurface->getBasePtr(x1 + w - 1 - r, y1 + r);
PixelType *ptr_bl = (PixelType *)Base::_activeSurface->getBasePtr(x1 + r, y1 + h - 1 - r);
PixelType *ptr_br = (PixelType *)Base::_activeSurface->getBasePtr(x1 + w - 1 - r, y1 + h - 1 - r);
PixelType *ptr_fill = (PixelType *)Base::_activeSurface->getBasePtr(x1, y1);

int short_h = h - 2 * r;
Expand Down Expand Up @@ -4214,7 +4214,7 @@ drawInteriorRoundedSquareAlg(int x1, int y1, int r, int w, int h, PixelType colo

ptr_fill += pitch * r;
while (short_h-- >= 0) {
colorFill<PixelType>(ptr_fill, ptr_fill + w + 1, color);
colorFill<PixelType>(ptr_fill, ptr_fill + w, color);
ptr_fill += pitch;
}
}
Expand Down

0 comments on commit 2d8e057

Please sign in to comment.