Skip to content

Conversation

@rly09
Copy link

@rly09 rly09 commented Dec 7, 2025

Summary by Sourcery

Bug Fixes:

  • Prevent a potential null pointer dereference in Win32Window::WndProc when handling window messages after creation.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Dec 7, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors Win32Window::WndProc to avoid a potential null pointer dereference by always returning DefWindowProc immediately after handling WM_NCCREATE and by guarding subsequent use of the window instance pointer with a null check.

Sequence diagram for updated Win32Window::WndProc message handling

sequenceDiagram
    participant OS
    participant Win32Window_WndProc as Win32Window_WndProc
    participant GetThisFromHandle
    participant Win32Window_MessageHandler as Win32Window_MessageHandler
    participant DefWindowProc

    OS->>Win32Window_WndProc: WndProc(window, message, wparam, lparam)
    alt message is WM_NCCREATE
        Win32Window_WndProc->>OS: Get CREATESTRUCT and lpCreateParams
        OS-->>Win32Window_WndProc: CREATESTRUCT with Win32Window pointer
        Win32Window_WndProc->>Win32Window_WndProc: EnableFullDpiSupportIfAvailable(window)
        Win32Window_WndProc->>Win32Window_WndProc: set window_handle_
        Win32Window_WndProc->>DefWindowProc: DefWindowProc(window, message, wparam, lparam)
        DefWindowProc-->>OS: LRESULT
    else any other message
        Win32Window_WndProc->>GetThisFromHandle: GetThisFromHandle(window)
        GetThisFromHandle-->>Win32Window_WndProc: Win32Window pointer or null
        alt Win32Window pointer not null
            Win32Window_WndProc->>Win32Window_MessageHandler: MessageHandler(window, message, wparam, lparam)
            Win32Window_MessageHandler-->>OS: LRESULT
        else Win32Window pointer is null
            Win32Window_WndProc-->>OS: 0 or default LRESULT
        end
    end
Loading

Class diagram for Win32Window with updated WndProc behavior

classDiagram
    class Win32Window {
        HWND window_handle_
        +static LRESULT CALLBACK WndProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam)
        +LRESULT MessageHandler(HWND window, UINT message, WPARAM wparam, LPARAM lparam)
        +static Win32Window* GetThisFromHandle(HWND window)
        +static void EnableFullDpiSupportIfAvailable(HWND window)
    }
Loading

File-Level Changes

Change Details Files
Harden Win32Window::WndProc against null pointer dereference when retrieving the Win32Window instance pointer.
  • Return DefWindowProc immediately after processing WM_NCCREATE, instead of falling through to further message handling
  • Move retrieval of the Win32Window instance pointer (GetThisFromHandle) outside the else-if chain for clarity
  • Add an explicit null check on the Win32Window instance pointer before calling MessageHandler
windows/runner/win32_window.cpp

Possibly linked issues

  • #(not specified): PR adds a null check around GetThisFromHandle and adjusts WM_NCCREATE flow, directly fixing the reported crash risk.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • The potential null dereference still exists in the WM_NCCREATE path: that is used without checking whether window_struct->lpCreateParams (and thus that) is non-null before assigning that->window_handle_, so consider adding a null check or early return before dereferencing.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The potential null dereference still exists in the WM_NCCREATE path: `that` is used without checking whether `window_struct->lpCreateParams` (and thus `that`) is non-null before assigning `that->window_handle_`, so consider adding a null check or early return before dereferencing.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant