fix(favorites): 🐛 fixing NPE crash on favorites manipulation #470#553
fix(favorites): 🐛 fixing NPE crash on favorites manipulation #470#553
Conversation
🤖 Augment PR SummarySummary: This PR hardens selection/favorites actions in the interactive UI to prevent crashes when manipulating favorites or deleting entries. Changes:
Technical Notes: The primary fix is avoiding invalid selection dereferences (empty selection) that could previously lead to NULL/invalid pointer access during favorites manipulation (#470). 🤖 Was this summary useful? React with 👍 or 👎 |
| break; | ||
| case KEY_DC: // DEL | ||
| if(selectionCursorPosition!=SELECTION_CURSOR_IN_PROMPT) { | ||
| if(selectionCursorPosition!=SELECTION_CURSOR_IN_PROMPT && hstr->selectionSize>0) { |
There was a problem hiding this comment.
getResultFromSelection() directly indexes hstr->selection[...]; hstr->selectionSize > 0 avoids the empty-list case but doesn’t ensure selectionCursorPosition maps to a valid element (e.g., cursor on a blank row when promptItems > selectionSize). Consider guarding the cursor/index range before calling it here (and in the other key handlers) to avoid out-of-bounds/UB crashes.
Other Locations
src/hstr.c:1502src/hstr.c:1648src/hstr.c:1664src/hstr.c:1682
🤖 Was this useful? React with 👍 or 👎
There was a problem hiding this comment.
Pull request overview
This PR fixes a null pointer exception crash that occurs when attempting to manipulate favorites or delete entries when the selection list is empty. The issue was caused by getResultFromSelection() attempting to access a null or out-of-bounds array when selectionSize is 0.
Changes:
- Added
hstr->selectionSize>0guards to all 5 call sites ofgetResultFromSelection()to prevent accessing the selection array when empty - Added defensive null checks for the return values in critical code paths (delete and favorite operations)
- Properly indented and restructured the affected code blocks to nest operations within the new safety guards
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Related: