From 0b51260540e488b2a4b06984ad9d20df7f91d07c Mon Sep 17 00:00:00 2001 From: John Hood Date: Mon, 19 Oct 2015 02:03:35 -0400 Subject: [PATCH] Fix for UTF-8 roundtrip verification bug. The problem was that the round-trip verification code copies the current state, which may contain intermediate Parser state for multibyte characters and ANSI escape sequences. It then applies diffs to that copy, which may appear as badly formed input. Also removes some dead, never-used code. --- src/network/transportsender.h | 7 ++++++- src/statesync/completeterminal.cc | 4 ++-- src/statesync/completeterminal.h | 3 +-- src/terminal/parser.h | 13 ++++++------- src/terminal/terminalframebuffer.cc | 5 +++-- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/network/transportsender.h b/src/network/transportsender.h index 572c47f..9ad3848 100644 --- a/src/network/transportsender.h +++ b/src/network/transportsender.h @@ -138,7 +138,12 @@ namespace Network { /* Misc. getters and setters */ /* Cannot modify current_state while shutdown in progress */ MyState &get_current_state( void ) { assert( !shutdown_in_progress ); return current_state; } - void set_current_state( const MyState &x ) { assert( !shutdown_in_progress ); current_state = x; } + void set_current_state( const MyState &x ) + { + assert( !shutdown_in_progress ); + current_state = x; + current_state.reset_input(); + } void set_verbose( void ) { verbose = true; } bool get_shutdown_in_progress( void ) const { return shutdown_in_progress; } diff --git a/src/statesync/completeterminal.cc b/src/statesync/completeterminal.cc index 7cfe1bf..07e76bd 100644 --- a/src/statesync/completeterminal.cc +++ b/src/statesync/completeterminal.cc @@ -174,8 +174,8 @@ int Complete::wait_time( uint64_t now ) const bool Complete::compare( const Complete &other ) const { bool ret = false; - for ( int x = 0; x < terminal.get_fb().ds.get_width(); x++ ) { - for ( int y = 0; y < terminal.get_fb().ds.get_height(); y++ ) { + for ( int y = 0; y < terminal.get_fb().ds.get_height(); y++ ) { + for ( int x = 0; x < terminal.get_fb().ds.get_width(); x++ ) { if ( terminal.get_fb().get_cell( y, x )->compare( *other.terminal.get_fb().get_cell( y, x ) ) ) { fprintf( stderr, "Cell (%d, %d) differs.\n", y, x ); ret = true; diff --git a/src/statesync/completeterminal.h b/src/statesync/completeterminal.h index 8dc8aca..13bdf56 100644 --- a/src/statesync/completeterminal.h +++ b/src/statesync/completeterminal.h @@ -67,8 +67,7 @@ namespace Terminal { std::string act( const Parser::Action *act ); const Framebuffer & get_fb( void ) const { return terminal.get_fb(); } - bool parser_grounded( void ) const { return parser.is_grounded(); } - + void reset_input( void ) { parser.reset_input(); } uint64_t get_echo_ack( void ) const { return echo_ack; } bool set_echo_ack( uint64_t now ); void register_input_frame( uint64_t n, uint64_t now ); diff --git a/src/terminal/parser.h b/src/terminal/parser.h index 08d66f8..c2979b5 100644 --- a/src/terminal/parser.h +++ b/src/terminal/parser.h @@ -60,12 +60,11 @@ namespace Parser { void input( wchar_t ch, Actions &actions ); - bool operator==( const Parser &x ) const + void reset_input( void ) { - return state == x.state; + state = &family.s_Ground; } - bool is_grounded( void ) const { return state == &family.s_Ground; } }; static const size_t BUF_SIZE = 8; @@ -82,12 +81,12 @@ namespace Parser { void input( char c, Actions &actions ); - bool operator==( const UTF8Parser &x ) const + void reset_input( void ) { - return parser == x.parser; + parser.reset_input(); + buf[0] = '\0'; + buf_len = 0; } - - bool is_grounded( void ) const { return parser.is_grounded(); } }; } diff --git a/src/terminal/terminalframebuffer.cc b/src/terminal/terminalframebuffer.cc index ad94d8a..0a36744 100644 --- a/src/terminal/terminalframebuffer.cc +++ b/src/terminal/terminalframebuffer.cc @@ -662,8 +662,9 @@ bool Cell::compare( const Cell &other ) const if ( !contents_match( other ) ) { ret = true; - fprintf( stderr, "Contents: %lc vs. %lc\n", - debug_contents(), other.debug_contents() ); + fprintf( stderr, "Contents: %lc (%ld) vs. %lc (%ld)\n", + debug_contents(), contents.size(), + other.debug_contents(), other.contents.size() ); } if ( fallback != other.fallback ) {