Skip to content

Commit

Permalink
Fix crash in rounding of shared images.
Browse files Browse the repository at this point in the history
Regression was introduced in 721d143.
  • Loading branch information
john-preston committed Feb 25, 2020
1 parent be5ed00 commit ccc12ce
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ui/image/image_prepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,17 @@ void prepareRound(
if (imageWidth < 2 * cornerWidth || imageHeight < 2 * cornerHeight) {
return;
}

// We need to detach image first (if it is shared), before we
// count some offsets using QImage::bytesPerLine etc, because
// bytesPerLine may change on detach, this leads to crashes:
// Real image bytesPerLine is smaller than the one we use for offsets.
auto ints = reinterpret_cast<uint32*>(image.bits());

constexpr auto imageIntsPerPixel = 1;
auto imageIntsPerLine = (image.bytesPerLine() >> 2);
Assert(image.depth() == static_cast<int>((imageIntsPerPixel * sizeof(uint32)) << 3));
Assert(image.bytesPerLine() == (imageIntsPerLine << 2));

auto ints = reinterpret_cast<uint32*>(image.bits());
auto intsTopLeft = ints + target.x() + target.y() * imageIntsPerLine;
auto intsTopRight = ints + target.x() + target.width() - cornerWidth + target.y() * imageIntsPerLine;
auto intsBottomLeft = ints + target.x() + (target.y() + target.height() - cornerHeight) * imageIntsPerLine;
Expand Down

0 comments on commit ccc12ce

Please sign in to comment.