Skip to content

Commit

Permalink
Fix bug in doing a save/restore of updown_match.
Browse files Browse the repository at this point in the history
Previously this was done by saving the value of updown_match,
but recently updown_match was split into two varibles.
Need to save/restore have_updown_match as well.

This is yet another bug caused by a change in
2d0abe8.
  • Loading branch information
gwsw committed May 14, 2024
1 parent 660bc14 commit 855ab5c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
18 changes: 17 additions & 1 deletion cmdbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,23 @@ static int cmd_updown(int action)
bell();
return (CC_OK);
}
#endif

/*
* Yet another lesson in the evils of global variables.
*/
public ssize_t save_updown_match(void)
{
if (!have_updown_match)
return (ssize_t)(-1);
return (ssize_t) updown_match;
}

public void restore_updown_match(ssize_t udm)
{
updown_match = udm;
have_updown_match = (udm != (ssize_t)(-1));
}
#endif /* CMD_HISTORY */

/*
*
Expand Down
6 changes: 3 additions & 3 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ extern void *ml_search;
extern void *ml_examine;
extern int wheel_lines;
extern int def_search_type;
extern int updown_match;
extern lbool search_wrapped;
#if SHELL_ESCAPE || PIPEC
extern void *ml_shell;
Expand Down Expand Up @@ -726,7 +725,7 @@ static int mca_char(char c)
{
/* Incremental search: do a search after every input char. */
int st = (search_type & (SRCH_FORW|SRCH_BACK|SRCH_NO_MATCH|SRCH_NO_REGEX|SRCH_NO_MOVE|SRCH_WRAP|SRCH_SUBSEARCH_ALL));
int save_updown_match = updown_match;
ssize_t save_updown;
constant char *pattern = get_cmdbuf();
if (pattern == NULL)
return (MCA_MORE);
Expand All @@ -735,6 +734,7 @@ static int mca_char(char c)
* reinits it. That breaks history scrolling.
* {{ This is ugly. mca_search probably shouldn't call set_mlist. }}
*/
save_updown = save_updown_match();
cmd_exec();
if (*pattern == '\0')
{
Expand All @@ -753,7 +753,7 @@ static int mca_char(char c)
repaint();
}
mca_search1();
updown_match = save_updown_match;
restore_updown_match(save_updown);
cmd_repaint(NULL);
}
break;
Expand Down

0 comments on commit 855ab5c

Please sign in to comment.