Skip to content

Commit

Permalink
Always pass 9 parameters to tparm()
Browse files Browse the repository at this point in the history
Some implementations like NetBSD have a non-variadic prototype of
tparm() requiring 9 explicit parameters. Therefore always make sure to
pass 9 parameters. Since other implementations uses a variadic prototype
it will work on them as well.

Inspired by how this solved in the portable version of tmux.

Spotted by Jenz Guenther in PR #216.
  • Loading branch information
mptre committed Jul 30, 2017
1 parent 421197e commit eea9ffc
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pick.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ static const char *strcasechr(const char *, const char *);
static int tty_getc(void);
static const char *tty_getcap(char *);
static void tty_init(void);
static const char *tty_parm1(const char *, int);
static int tty_putc(int);
static void tty_restore(void);
static __dead void usage(void);
Expand Down Expand Up @@ -311,13 +312,14 @@ selected_choice(void)
if (tty_putc('\n') == EOF)
err(1, "tty_putc");
tty_putp(clr_eos, 1);
tty_putp(tparm(parm_up_cursor, choices_count + 1), 1);
tty_putp(tty_parm1(parm_up_cursor, choices_count + 1),
1);
} else if (choices_count > 0) {
/*
* parm_up_cursor interprets 0 as 1, therefore only move
* upwards if any choices where printed.
*/
tty_putp(tparm(parm_up_cursor,
tty_putp(tty_parm1(parm_up_cursor,
choices_count < choices_lines
? choices_count : choices_lines), 1);
}
Expand All @@ -330,7 +332,7 @@ selected_choice(void)
* parm_right_cursor interprets 0 as 1, therefore only
* move the cursor if the position is non zero.
*/
tty_putp(tparm(parm_right_cursor, j), 1);
tty_putp(tty_parm1(parm_right_cursor, j), 1);
tty_putp(cursor_normal, 0);
fflush(tty_out);

Expand Down Expand Up @@ -932,6 +934,12 @@ tty_getcap(char *cap)
return str;
}

const char *
tty_parm1(const char *cap, int a)
{
return tparm((char *)cap, a, 0, 0, 0, 0, 0, 0, 0, 0);
}

void
delete_between(char *string, size_t length, size_t start, size_t end)
{
Expand Down

0 comments on commit eea9ffc

Please sign in to comment.