Skip to content

Commit

Permalink
Fix potential null pointer access (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
tishion authored Jun 17, 2022
1 parent bddf16f commit 3b9ee2a
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/details/CCefClientDelegate_RenderHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "CCefClientDelegate.h"
#include "CCefClientDelegate.h"

#include <QApplication>
#include <QDebug>
Expand All @@ -16,13 +16,15 @@ CCefClientDelegate::GetRootScreenRect(CefRefPtr<CefBrowser> browser, CefRect& re
return false;
}

// get the screen which the view is current residing at
// get the screen which the view is currently residing in
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QScreen* currentScreen = pCefViewPrivate_->q_ptr->window()->screen();
QScreen* currentScreen = pCefViewPrivate_->q_ptr->screen();
#else
QWindow window = pCefViewPrivate_->q_ptr->window()->windowHandle();
QScreen* currentScreen = window ? window->screen() : nullptr;
QWidget* ancestorWidget = pCefViewPrivate_->q_ptr->window();
QWindow* ancestorWindow = ancestorWidget ? ancestorWidget->windowHandle() : nullptr;
QScreen* currentScreen = ancestorWindow ? ancestorWindow->screen() : nullptr;
#endif

if (!currentScreen) {
// the view is not visible so we retrieve the main screen info
currentScreen = QApplication::screens().at(0);
Expand Down Expand Up @@ -73,9 +75,16 @@ CCefClientDelegate::GetScreenInfo(CefRefPtr<CefBrowser> browser, CefScreenInfo&
{
if (!IsValidBrowser(browser))
return false;

// get the screen which the view is current residing at
QScreen* currentScreen = pCefViewPrivate_->q_ptr->window()->screen();

// get the screen which the view is currently residing in
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QScreen* currentScreen = pCefViewPrivate_->q_ptr->screen();
#else
QWidget* ancestorWidget = pCefViewPrivate_->q_ptr->window();
QWindow* ancestorWindow = ancestorWidget ? ancestorWidget->windowHandle() : nullptr;
QScreen* currentScreen = ancestorWindow ? ancestorWindow->screen() : nullptr;
#endif

if (!currentScreen) {
// the view is not visible so we retrieve the main screen info
currentScreen = QApplication::screens().at(0);
Expand Down

0 comments on commit 3b9ee2a

Please sign in to comment.