From da35e9d5efa0e3f5e5582c633dfc093847ed6fc0 Mon Sep 17 00:00:00 2001 From: Yuuki Harano Date: Sun, 16 Jan 2022 17:25:28 +0900 Subject: [PATCH] * src/pgtkterm.c (evq_flush): Shift events one by one --- src/pgtkterm.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/pgtkterm.c b/src/pgtkterm.c index 0155ae991d3..4c38ff5a597 100644 --- a/src/pgtkterm.c +++ b/src/pgtkterm.c @@ -153,10 +153,24 @@ static int evq_flush (struct input_event *hold_quit) { struct event_queue_t *evq = &event_q; - int i, n = evq->nr; - for (i = 0; i < n; i++) - kbd_buffer_store_buffered_event (&evq->q[i], hold_quit); - evq->nr = 0; + int n = 0; + + while (evq->nr > 0) + { + /* kbd_buffer_store_buffered_event may do longjmp, so + we need to shift event queue first and pass the event + to kbd_buffer_store_buffered_event so that events in + queue are not processed twice. Bug#52941 */ + union buffered_input_event ev = evq->q[0]; + int i; + for (i = 1; i < evq->nr; i++) + evq->q[i - 1] = evq->q[i]; + evq->nr--; + + kbd_buffer_store_buffered_event (&ev, hold_quit); + n++; + } + return n; } -- 2.39.2