Skip to content

Commit

Permalink
Possible fix for crash in Window::limitPosition() when parent is null…
Browse files Browse the repository at this point in the history
…ptr (fix aseprite#4261)

We cannot reproduce this but just adding a check here to avoid using a
nullptr parent pointer.
  • Loading branch information
dacap committed Jan 8, 2024
1 parent 0089410 commit 9d69cb8
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/ui/window.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2018-2023 Igara Studio S.A.
// Copyright (C) 2018-2024 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This file is released under the terms of the MIT license.
Expand Down Expand Up @@ -765,12 +765,17 @@ void Window::limitSize(gfx::Size& size)

void Window::limitPosition(gfx::Rect& rect)
{
auto parent = this->parent();
ASSERT(parent);
if (!parent)
return;

if (rect.y < 0) {
rect.y = 0;
rect.h = bounds().h;
}
auto titlebarH = childrenBounds().y - bounds().y;
auto limitB = parent()->bounds().y2() - titlebarH;
auto limitB = parent->bounds().y2() - titlebarH;
if (rect.y > limitB) {
rect.y = limitB;
rect.h = bounds().h;
Expand All @@ -781,7 +786,7 @@ void Window::limitPosition(gfx::Rect& rect)
rect.x = limitL;
rect.w = bounds().w;
}
auto limitR = parent()->bounds().x2() - border().right();
auto limitR = parent->bounds().x2() - border().right();
if (rect.x > limitR) {
rect.x = limitR;
rect.w = bounds().w;
Expand Down

0 comments on commit 9d69cb8

Please sign in to comment.