Commit 6cc5a511 authored by Martin Tobias Holmedahl Sandsmark's avatar Martin Tobias Holmedahl Sandsmark
Browse files

Fix segfault/call on invalid pointer

We didn't set the AbstractImageView in AbstractImageViewPrivate early
enough, and createAlphaBackgroundTexture() tried to call stuff on q.

Quote from asan:

==161679==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7fa8cdcc193a bp 0x7ffe601e4a00 sp 0x7ffe601e48f0 T0)
==161679==The signal is caused by a READ memory access.
==161679==Hint: address points to the zero page.
    #0 0x7fa8cdcc1939 in Gwenview::AbstractImageViewPrivate::createAlphaBackgroundTexture() (gwenview/build/bin/libgwenviewlib.so.5+0x108a939)
    #1 0x7fa8cdcc28b8 in Gwenview::AbstractImageViewPrivate::AbstractImageViewPrivate() (gwenview/build/bin/libgwenviewlib.so.5+0x108b8b8)
    #2 0x7fa8cdca46a2 in Gwenview::AbstractImageView::AbstractImageView(QGraphicsItem*) ../lib/documentview/abstractimageview.cpp:145
    #3 0x7fa8cdd500a5 in Gwenview::RasterImageView::RasterImageView(QGraphicsItem*) ../lib/documentview/rasterimageview.cpp:194

Reviewed By: ngraham

Differential Revision: https://phabricator.kde.org/D28345
parent 0d36aa4a
...@@ -60,7 +60,7 @@ struct AbstractImageViewPrivate ...@@ -60,7 +60,7 @@ struct AbstractImageViewPrivate
QPointF mLastDragPos; QPointF mLastDragPos;
QSizeF mDocumentSize; QSizeF mDocumentSize;
const QPixmap mAlphaBackgroundTexture = createAlphaBackgroundTexture(); const QPixmap mAlphaBackgroundTexture;
void adjustImageOffset(Verbosity verbosity = Notify) void adjustImageOffset(Verbosity verbosity = Notify)
{ {
...@@ -128,6 +128,11 @@ struct AbstractImageViewPrivate ...@@ -128,6 +128,11 @@ struct AbstractImageViewPrivate
return pix; return pix;
} }
AbstractImageViewPrivate(AbstractImageView *parent) :
q(parent),
mAlphaBackgroundTexture(createAlphaBackgroundTexture())
{ }
void checkAndRequestZoomAction(const QGraphicsSceneMouseEvent* event) void checkAndRequestZoomAction(const QGraphicsSceneMouseEvent* event)
{ {
if (event->modifiers() & Qt::ControlModifier) { if (event->modifiers() & Qt::ControlModifier) {
...@@ -142,9 +147,8 @@ struct AbstractImageViewPrivate ...@@ -142,9 +147,8 @@ struct AbstractImageViewPrivate
AbstractImageView::AbstractImageView(QGraphicsItem* parent) AbstractImageView::AbstractImageView(QGraphicsItem* parent)
: QGraphicsWidget(parent) : QGraphicsWidget(parent)
, d(new AbstractImageViewPrivate) , d(new AbstractImageViewPrivate(this))
{ {
d->q = this;
d->mControlKeyIsDown = false; d->mControlKeyIsDown = false;
d->mEnlargeSmallerImages = false; d->mEnlargeSmallerImages = false;
d->mZoom = 1; d->mZoom = 1;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment