Skip to content

Commit 0f0f230

Browse files
committed
patch 8.0.1020: when a timer calls getchar(1) input is overwritten
Problem: When a timer calls getchar(1) input is overwritten. Solution: Increment tb_change_cnt in inchar(). (closes #1940)
1 parent d41babe commit 0f0f230

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

src/getchar.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static int vgetorpeek(int);
125125
static void map_free(mapblock_T **);
126126
static void validate_maphash(void);
127127
static void showmap(mapblock_T *mp, int local);
128-
static int inchar(char_u *buf, int maxlen, long wait_time, int tb_change_cnt);
128+
static int inchar(char_u *buf, int maxlen, long wait_time);
129129
#ifdef FEAT_EVAL
130130
static char_u *eval_map_expr(char_u *str, int c);
131131
#endif
@@ -462,8 +462,7 @@ flush_buffers(int flush_typeahead)
462462
* of an escape sequence.
463463
* In an xterm we get one char at a time and we have to get them all.
464464
*/
465-
while (inchar(typebuf.tb_buf, typebuf.tb_buflen - 1, 10L,
466-
typebuf.tb_change_cnt) != 0)
465+
while (inchar(typebuf.tb_buf, typebuf.tb_buflen - 1, 10L) != 0)
467466
;
468467
typebuf.tb_off = MAXMAPLEN;
469468
typebuf.tb_len = 0;
@@ -2046,8 +2045,7 @@ vgetorpeek(int advance)
20462045
if (got_int)
20472046
{
20482047
/* flush all input */
2049-
c = inchar(typebuf.tb_buf, typebuf.tb_buflen - 1, 0L,
2050-
typebuf.tb_change_cnt);
2048+
c = inchar(typebuf.tb_buf, typebuf.tb_buflen - 1, 0L);
20512049
/*
20522050
* If inchar() returns TRUE (script file was active) or we
20532051
* are inside a mapping, get out of insert mode.
@@ -2610,8 +2608,7 @@ vgetorpeek(int advance)
26102608
&& (p_timeout
26112609
|| (keylen == KEYLEN_PART_KEY && p_ttimeout))
26122610
&& (c = inchar(typebuf.tb_buf + typebuf.tb_off
2613-
+ typebuf.tb_len, 3, 25L,
2614-
typebuf.tb_change_cnt)) == 0)
2611+
+ typebuf.tb_len, 3, 25L)) == 0)
26152612
{
26162613
colnr_T col = 0, vcol;
26172614
char_u *ptr;
@@ -2848,7 +2845,7 @@ vgetorpeek(int advance)
28482845
? -1L
28492846
: ((keylen == KEYLEN_PART_KEY && p_ttm >= 0)
28502847
? p_ttm
2851-
: p_tm)), typebuf.tb_change_cnt);
2848+
: p_tm)));
28522849

28532850
#ifdef FEAT_CMDL_INFO
28542851
if (i != 0)
@@ -2954,12 +2951,12 @@ vgetorpeek(int advance)
29542951
inchar(
29552952
char_u *buf,
29562953
int maxlen,
2957-
long wait_time, /* milli seconds */
2958-
int tb_change_cnt)
2954+
long wait_time) /* milli seconds */
29592955
{
29602956
int len = 0; /* init for GCC */
29612957
int retesc = FALSE; /* return ESC with gotint */
29622958
int script_char;
2959+
int tb_change_cnt = typebuf.tb_change_cnt;
29632960

29642961
if (wait_time == -1L || wait_time > 100L) /* flush output before waiting */
29652962
{
@@ -3065,9 +3062,17 @@ inchar(
30653062
len = ui_inchar(buf, maxlen / 3, wait_time, tb_change_cnt);
30663063
}
30673064

3065+
/* If the typebuf was changed further down, it is like nothing was added by
3066+
* this call. */
30683067
if (typebuf_changed(tb_change_cnt))
30693068
return 0;
30703069

3070+
/* Note the change in the typeahead buffer, this matters for when
3071+
* vgetorpeek() is called recursively, e.g. using getchar(1) in a timer
3072+
* function. */
3073+
if (len > 0 && ++typebuf.tb_change_cnt == 0)
3074+
typebuf.tb_change_cnt = 1;
3075+
30713076
return fix_input_buffer(buf, len);
30723077
}
30733078

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,8 @@ static char *(features[]) =
769769

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
1020,
772774
/**/
773775
1019,
774776
/**/

0 commit comments

Comments
 (0)