Skip to content

fix(favorites): 🐛 fixing NPE crash on favorites manipulation #470#553

Open
dvorka wants to merge 1 commit intodev-3.2.0from
bug-470/favorites-crash
Open

fix(favorites): 🐛 fixing NPE crash on favorites manipulation #470#553
dvorka wants to merge 1 commit intodev-3.2.0from
bug-470/favorites-crash

Conversation

@dvorka
Copy link
Owner

@dvorka dvorka commented Jan 26, 2026

@augmentcode
Copy link

augmentcode bot commented Jan 26, 2026

🤖 Augment PR Summary

Summary: This PR hardens selection/favorites actions in the interactive UI to prevent crashes when manipulating favorites or deleting entries.

Changes:

  • Added guards so DEL / Ctrl+F / Enter / Left / Right only act on a non-empty selection.
  • Added NULL checks before using the selected command in delete/favorites paths.
  • Kept cursor/selection highlighting updates after delete to maintain a valid selection state.

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 👎

Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

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

Review completed. 1 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

break;
case KEY_DC: // DEL
if(selectionCursorPosition!=SELECTION_CURSOR_IN_PROMPT) {
if(selectionCursorPosition!=SELECTION_CURSOR_IN_PROMPT && hstr->selectionSize>0) {
Copy link

Choose a reason for hiding this comment

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

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:1502
  • src/hstr.c:1648
  • src/hstr.c:1664
  • src/hstr.c:1682

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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>0 guards to all 5 call sites of getResultFromSelection() 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.

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