Restore asserts and error handling

A couple of them got improved out of existence.
This commit is contained in:
John Hood
2017-08-13 00:27:23 -04:00
parent 790b479f8a
commit b11d524bb7
6 changed files with 27 additions and 22 deletions
+2 -1
View File
@@ -298,8 +298,9 @@ void NotificationEngine::apply( Framebuffer &fb ) const
} }
break; break;
case -1: /* unprintable character */ case -1: /* unprintable character */
default: /* Bogus width, ignore. */
break; break;
default:
assert( !"unexpected character width from wcwidth()" );
} }
} }
} }
+3 -6
View File
@@ -335,7 +335,8 @@ bool Connection::try_bind( const char *addr, int port_low, int port_high )
if ( bind( sock(), &local_addr.sa, local_addr_len ) == 0 ) { if ( bind( sock(), &local_addr.sa, local_addr_len ) == 0 ) {
set_MTU( local_addr.sa.sa_family ); set_MTU( local_addr.sa.sa_family );
return true; return true;
} else if ( i == search_high ) { /* last port to search */ } // else fallthrough to below code, on last iteration.
}
int saved_errno = errno; int saved_errno = errno;
socks.pop_back(); socks.pop_back();
char host[ NI_MAXHOST ], serv[ NI_MAXSERV ]; char host[ NI_MAXHOST ], serv[ NI_MAXSERV ];
@@ -349,10 +350,6 @@ bool Connection::try_bind( const char *addr, int port_low, int port_high )
host, serv ); host, serv );
throw NetworkException( "bind", saved_errno ); throw NetworkException( "bind", saved_errno );
} }
}
return false;
}
Connection::Connection( const char *key_str, const char *ip, const char *port ) /* client */ Connection::Connection( const char *key_str, const char *ip, const char *port ) /* client */
: socks(), : socks(),
@@ -456,7 +453,7 @@ string Connection::recv( void )
prune_sockets(); prune_sockets();
return payload; return payload;
} }
return ""; throw NetworkException( "No packet received" );
} }
string Connection::recv_one( int sock_to_recv, bool nonblocking ) string Connection::recv_one( int sock_to_recv, bool nonblocking )
+2
View File
@@ -95,6 +95,7 @@ string UserStream::diff_from( const UserStream &existing ) const
} }
break; break;
default: default:
assert( !"unexpected event type" );
break; break;
} }
@@ -130,6 +131,7 @@ const Parser::Action &UserStream::get_action( unsigned int i ) const
case ResizeType: case ResizeType:
return actions[ i ].resize; return actions[ i ].resize;
default: default:
assert( !"unexpected action type" );
static const Parser::Ignore nothing = Parser::Ignore(); static const Parser::Ignore nothing = Parser::Ignore();
return nothing; return nothing;
} }
+1 -1
View File
@@ -85,7 +85,7 @@ namespace Network {
/* interface for Network::Transport */ /* interface for Network::Transport */
void subtract( const UserStream *prefix ); void subtract( const UserStream *prefix );
string diff_from( const UserStream &existing ) const; string diff_from( const UserStream &existing ) const;
string init_diff( void ) const { return string(); }; string init_diff( void ) const { return diff_from( UserStream() ); };
void apply_string( const string &diff ); void apply_string( const string &diff );
bool operator==( const UserStream &x ) const { return actions == x.actions; } bool operator==( const UserStream &x ) const { return actions == x.actions; }
+3 -1
View File
@@ -140,7 +140,9 @@ void Emulator::print( const Parser::Print *act )
} }
break; break;
case -1: /* unprintable character */ case -1: /* unprintable character */
default: /* bogus width, ignore */ break;
default:
assert( !"unexpected character width from wcwidth()" );
break; break;
} }
} }
+5 -2
View File
@@ -46,6 +46,9 @@ string UserInput::input( const Parser::UserByte *act,
/* We need to look ahead one byte in the SS3 state to see if /* We need to look ahead one byte in the SS3 state to see if
the next byte will be A, B, C, or D (cursor control keys). */ the next byte will be A, B, C, or D (cursor control keys). */
/* This doesn't handle the 8-bit SS3 C1 control, which would be
two octets in UTF-8. Fortunately nobody seems to send this. */
switch ( state ) { switch ( state ) {
case Ground: case Ground:
if ( act->c == 0x1b ) { /* ESC */ if ( act->c == 0x1b ) { /* ESC */
@@ -74,8 +77,8 @@ string UserInput::input( const Parser::UserByte *act,
} }
default: default:
/* This doesn't handle the 8-bit SS3 C1 control, which would be assert( !"unexpected state" );
two octets in UTF-8. Fortunately nobody seems to send this. */ state = Ground;
return string(); return string();
} }
} }