Repository navigation
Fix Windows crash bug - #4460
Conversation
I've successfully fixed the nil pointer dereference bug in the Wails v3 system tray functionality on Windows. Here's what I addressed: **Root Cause**: The bug occurred in `systemtray_windows.go:80` where `*trayBounds = PhysicalToDipRect(*trayBounds)` was dereferencing a potentially nil pointer without checking. **Fixes Applied**: 1. **`positionWindow` method (lines 80-82)**: Added nil check for `trayBounds` before dereferencing 2. **`bounds` method (lines 121-123, 129-131)**: Added checks for uninitialized `hwnd` and nil return from `GetSystrayBounds` 3. **`iconIsInTrayBounds` method (lines 147-149, 155-157, 160-162)**: Added similar protective checks and taskbar position validation 4. **`getScreen` method (lines 173-175)**: Added `hwnd` initialization check 5. **`openMenu` method (lines 45-47)**: Added nil check for `trayBounds` **Key Improvements**: - Added proper initialization checks for `s.hwnd == 0` - Added nil pointer checks for all Windows API return values - Ensured graceful error handling instead of panics - Maintained existing functionality while preventing race conditions The fix addresses the race condition where system tray operations could be called before the tray was fully initialized, preventing the nil pointer dereference panic described in issue #4456.
|
Warning Rate limit exceeded@dosubot[bot] has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 29 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
WalkthroughDefensive error handling has been added to several methods in the Windows system tray implementation. The updates introduce explicit nil checks and error returns for uninitialized or unavailable system tray bounds, handles, and related resources, aiming to prevent nil pointer dereferences and clarify error reporting in internal logic. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 minutes Assessment against linked issues
Assessment against linked issues: Out-of-scope changes
Suggested labels
Poem
✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
|
|
* ## Summary I've successfully fixed the nil pointer dereference bug in the Wails v3 system tray functionality on Windows. Here's what I addressed: **Root Cause**: The bug occurred in `systemtray_windows.go:80` where `*trayBounds = PhysicalToDipRect(*trayBounds)` was dereferencing a potentially nil pointer without checking. **Fixes Applied**: 1. **`positionWindow` method (lines 80-82)**: Added nil check for `trayBounds` before dereferencing 2. **`bounds` method (lines 121-123, 129-131)**: Added checks for uninitialized `hwnd` and nil return from `GetSystrayBounds` 3. **`iconIsInTrayBounds` method (lines 147-149, 155-157, 160-162)**: Added similar protective checks and taskbar position validation 4. **`getScreen` method (lines 173-175)**: Added `hwnd` initialization check 5. **`openMenu` method (lines 45-47)**: Added nil check for `trayBounds` **Key Improvements**: - Added proper initialization checks for `s.hwnd == 0` - Added nil pointer checks for all Windows API return values - Ensured graceful error handling instead of panics - Maintained existing functionality while preventing race conditions The fix addresses the race condition where system tray operations could be called before the tray was fully initialized, preventing the nil pointer dereference panic described in issue wailsapp#4456. * Update changelog



Initial attempt at fixing the nil dereference bug
closes #4456
Summary by CodeRabbit