[vte] emulation: Fix crash in restore-cursor without a preceding save-cursor
- From: Egmont Koblinger <egmontkob src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte] emulation: Fix crash in restore-cursor without a preceding save-cursor
- Date: Sun, 7 Dec 2014 12:43:56 +0000 (UTC)
commit e549a0eebc82fde89134c15ead322dc199d99239
Author: Egmont Koblinger <egmont gmail com>
Date: Sun Dec 7 13:41:49 2014 +0100
emulation: Fix crash in restore-cursor without a preceding save-cursor
https://bugzilla.gnome.org/show_bug.cgi?id=741193
src/vte-private.h | 2 ++
src/vte.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++--
src/vteseq.c | 37 ++-----------------------------------
3 files changed, 52 insertions(+), 37 deletions(-)
---
diff --git a/src/vte-private.h b/src/vte-private.h
index 3e36b21..dded036 100644
--- a/src/vte-private.h
+++ b/src/vte-private.h
@@ -474,6 +474,8 @@ void _vte_terminal_queue_contents_changed(VteTerminal *terminal);
void _vte_terminal_emit_text_deleted(VteTerminal *terminal);
void _vte_terminal_emit_text_inserted(VteTerminal *terminal);
void _vte_terminal_cursor_down (VteTerminal *terminal);
+void _vte_terminal_restore_cursor (VteTerminal *terminal, VteScreen *screen);
+void _vte_terminal_save_cursor (VteTerminal *terminal, VteScreen *screen);
gboolean _vte_terminal_insert_char(VteTerminal *terminal, gunichar c,
gboolean force_insert_mode,
gboolean invalidate_cells);
diff --git a/src/vte.c b/src/vte.c
index f790a3b..22f54e9 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -3025,6 +3025,47 @@ _vte_terminal_cursor_down (VteTerminal *terminal)
}
}
+/* Restore cursor on a screen. */
+void
+_vte_terminal_restore_cursor (VteTerminal *terminal, VteScreen *screen)
+{
+ terminal->pvt->cursor.col = screen->saved.cursor.col;
+ terminal->pvt->cursor.row = screen->insert_delta + CLAMP(screen->saved.cursor.row,
+ 0, terminal->pvt->row_count - 1);
+
+ terminal->pvt->reverse_mode = screen->saved.reverse_mode;
+ terminal->pvt->origin_mode = screen->saved.origin_mode;
+ terminal->pvt->sendrecv_mode = screen->saved.sendrecv_mode;
+ terminal->pvt->insert_mode = screen->saved.insert_mode;
+ terminal->pvt->linefeed_mode = screen->saved.linefeed_mode;
+ terminal->pvt->defaults = screen->saved.defaults;
+ terminal->pvt->color_defaults = screen->saved.color_defaults;
+ terminal->pvt->fill_defaults = screen->saved.fill_defaults;
+ terminal->pvt->character_replacements[0] = screen->saved.character_replacements[0];
+ terminal->pvt->character_replacements[1] = screen->saved.character_replacements[1];
+ terminal->pvt->character_replacement = screen->saved.character_replacement;
+}
+
+/* Save cursor on a screen. */
+void
+_vte_terminal_save_cursor (VteTerminal *terminal, VteScreen *screen)
+{
+ screen->saved.cursor.col = terminal->pvt->cursor.col;
+ screen->saved.cursor.row = terminal->pvt->cursor.row - screen->insert_delta;
+
+ screen->saved.reverse_mode = terminal->pvt->reverse_mode;
+ screen->saved.origin_mode = terminal->pvt->origin_mode;
+ screen->saved.sendrecv_mode = terminal->pvt->sendrecv_mode;
+ screen->saved.insert_mode = terminal->pvt->insert_mode;
+ screen->saved.linefeed_mode = terminal->pvt->linefeed_mode;
+ screen->saved.defaults = terminal->pvt->defaults;
+ screen->saved.color_defaults = terminal->pvt->color_defaults;
+ screen->saved.fill_defaults = terminal->pvt->fill_defaults;
+ screen->saved.character_replacements[0] = terminal->pvt->character_replacements[0];
+ screen->saved.character_replacements[1] = terminal->pvt->character_replacements[1];
+ screen->saved.character_replacement = terminal->pvt->character_replacement;
+}
+
/* Insert a single character into the stored data array. */
gboolean
_vte_terminal_insert_char(VteTerminal *terminal, gunichar c,
@@ -8018,8 +8059,6 @@ vte_terminal_init(VteTerminal *terminal)
pvt->cursor_mode = VTE_KEYMODE_NORMAL;
pvt->autowrap = TRUE;
pvt->sendrecv_mode = TRUE;
- pvt->normal_screen.saved.sendrecv_mode = TRUE;
- pvt->alternate_screen.saved.sendrecv_mode = TRUE;
pvt->dec_saved = g_hash_table_new(NULL, NULL);
pvt->matcher = _vte_matcher_new();
pvt->alternate_screen_scroll = TRUE;
@@ -8065,6 +8104,10 @@ vte_terminal_init(VteTerminal *terminal)
* via escape sequence) */
pvt->cursor_style = VTE_CURSOR_STYLE_TERMINAL_DEFAULT;
+ /* Initialize the saved cursor. */
+ _vte_terminal_save_cursor(terminal, &terminal->pvt->normal_screen);
+ _vte_terminal_save_cursor(terminal, &terminal->pvt->alternate_screen);
+
/* Matching data. */
pvt->match_regexes = g_array_new(FALSE, TRUE,
sizeof(struct vte_match_regex));
@@ -11868,6 +11911,9 @@ vte_terminal_reset(VteTerminal *terminal,
pvt->modifiers = 0;
/* Reset miscellaneous stuff. */
pvt->bracketed_paste_mode = FALSE;
+ /* Reset the saved cursor. */
+ _vte_terminal_save_cursor(terminal, &terminal->pvt->normal_screen);
+ _vte_terminal_save_cursor(terminal, &terminal->pvt->alternate_screen);
/* Cause everything to be redrawn (or cleared). */
vte_terminal_maybe_scroll_to_bottom(terminal);
_vte_invalidate_all(terminal);
diff --git a/src/vteseq.c b/src/vteseq.c
index 5fc6358..629f6c1 100644
--- a/src/vteseq.c
+++ b/src/vteseq.c
@@ -414,48 +414,15 @@ _vte_terminal_scroll_text (VteTerminal *terminal, int scroll_amount)
static void
vte_sequence_handler_restore_cursor (VteTerminal *terminal, GValueArray *params)
{
- VteScreen *screen;
- screen = terminal->pvt->screen;
-
- terminal->pvt->cursor.col = screen->saved.cursor.col;
- terminal->pvt->cursor.row = screen->insert_delta + CLAMP(screen->saved.cursor.row,
- 0, terminal->pvt->row_count - 1);
+ _vte_terminal_restore_cursor(terminal, terminal->pvt->screen);
_vte_terminal_ensure_cursor_is_onscreen(terminal);
-
- terminal->pvt->reverse_mode = screen->saved.reverse_mode;
- terminal->pvt->origin_mode = screen->saved.origin_mode;
- terminal->pvt->sendrecv_mode = screen->saved.sendrecv_mode;
- terminal->pvt->insert_mode = screen->saved.insert_mode;
- terminal->pvt->linefeed_mode = screen->saved.linefeed_mode;
- terminal->pvt->defaults = screen->saved.defaults;
- terminal->pvt->color_defaults = screen->saved.color_defaults;
- terminal->pvt->fill_defaults = screen->saved.fill_defaults;
- terminal->pvt->character_replacements[0] = screen->saved.character_replacements[0];
- terminal->pvt->character_replacements[1] = screen->saved.character_replacements[1];
- terminal->pvt->character_replacement = screen->saved.character_replacement;
}
/* Save cursor. */
static void
vte_sequence_handler_save_cursor (VteTerminal *terminal, GValueArray *params)
{
- VteScreen *screen;
- screen = terminal->pvt->screen;
-
- screen->saved.cursor.col = terminal->pvt->cursor.col;
- screen->saved.cursor.row = terminal->pvt->cursor.row - screen->insert_delta;
-
- screen->saved.reverse_mode = terminal->pvt->reverse_mode;
- screen->saved.origin_mode = terminal->pvt->origin_mode;
- screen->saved.sendrecv_mode = terminal->pvt->sendrecv_mode;
- screen->saved.insert_mode = terminal->pvt->insert_mode;
- screen->saved.linefeed_mode = terminal->pvt->linefeed_mode;
- screen->saved.defaults = terminal->pvt->defaults;
- screen->saved.color_defaults = terminal->pvt->color_defaults;
- screen->saved.fill_defaults = terminal->pvt->fill_defaults;
- screen->saved.character_replacements[0] = terminal->pvt->character_replacements[0];
- screen->saved.character_replacements[1] = terminal->pvt->character_replacements[1];
- screen->saved.character_replacement = terminal->pvt->character_replacement;
+ _vte_terminal_save_cursor(terminal, terminal->pvt->screen);
}
/* Switch to normal screen. */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]