Skip to content

Commit b87d6a6

Browse files
committed
Add missing bounds check in mac screen color picker
1 parent e95d4f9 commit b87d6a6

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/osx/screenpicker.mm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@
2929
namespace {
3030

3131
void CopyToDC(CGImageRef img, wxMemoryDC &capdc, int resx, int resy, int magnification) {
32-
size_t width = CGImageGetWidth(img);
33-
size_t height = CGImageGetHeight(img);
32+
int width = CGImageGetWidth(img);
33+
int height = CGImageGetHeight(img);
3434
std::vector<uint8_t> imgdata(height * width * 4);
3535

3636
agi::scoped_holder<CGColorSpaceRef> colorspace(CGColorSpaceCreateDeviceRGB(), CGColorSpaceRelease);
3737
agi::scoped_holder<CGContextRef> bmp_context(CGBitmapContextCreate(&imgdata[0], width, height, 8, 4 * width, colorspace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big), CGContextRelease);
3838

3939
CGContextDrawImage(bmp_context, CGRectMake(0, 0, width, height), img);
4040

41-
for (int x = 0; x < resx; x++) {
42-
for (int y = 0; y < resy; y++) {
41+
for (int x = 0; x < resx && x < width; x++) {
42+
for (int y = 0; y < resy && y < height; y++) {
4343
uint8_t *pixel = &imgdata[y * width * 4 + x * 4];
4444
capdc.SetBrush(wxBrush(wxColour(pixel[0], pixel[1], pixel[2])));
4545
capdc.DrawRectangle(x * magnification, y * magnification, magnification, magnification);

0 commit comments

Comments
 (0)