From 9d69cb8dfe07866d6b0c4191a09121070733ec78 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 8 Jan 2024 15:07:36 -0300 Subject: [PATCH] Possible fix for crash in Window::limitPosition() when parent is nullptr (fix #4261) We cannot reproduce this but just adding a check here to avoid using a nullptr parent pointer. --- src/ui/window.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ui/window.cpp b/src/ui/window.cpp index 0c5d3c236..16682f08e 100644 --- a/src/ui/window.cpp +++ b/src/ui/window.cpp @@ -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. @@ -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; @@ -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;