From 436b1e10c616880975a1e7a2b037232c96ba0507 Mon Sep 17 00:00:00 2001 From: axel Date: Thu, 22 Jun 2006 10:12:28 +1000 Subject: [PATCH] Fix infinite loop when trying to init history without setting history mode name first darcs-hash:20060622001228-ac50b-caa00ff803b6b1673d7672d8364f68afe89cee18.gz --- history.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/history.c b/history.c index dd7c5d7cd..ac25bc765 100644 --- a/history.c +++ b/history.c @@ -103,13 +103,19 @@ static int is_loaded=0; /** Load history from file */ -static void history_load() +static int history_load() { wchar_t *fn; wchar_t *buff=0; int buff_len=0; FILE *in_stream; hash_table_t used; + int res = 0; + + if( !mode_name ) + { + return -1; + } is_loaded = 1; @@ -136,7 +142,7 @@ static void history_load() free( fn ); free( buff ); signal_unblock(); - return; + return -1; } /* @@ -182,6 +188,8 @@ static void history_load() { debug( 1, L"The following non-fatal error occurred while reading command history from \'%ls\':", mode_name ); wperror( L"fopen" ); + res = -1; + } } @@ -193,6 +201,8 @@ static void history_load() free( fn ); last_loaded = history_last; signal_unblock(); + return res; + } void history_init() @@ -315,7 +325,9 @@ static void history_save() history_count=0; past_end=1; - history_load(); + if( !history_load() ) + { + if( real_pos != 0 ) { /* @@ -373,6 +385,8 @@ static void history_save() } free( fn ); } + } + } @@ -433,7 +447,13 @@ void history_destroy() static ll_node_t *history_find( ll_node_t *n, const wchar_t *s ) { if( !is_loaded ) - history_load(); + { + if( history_load() ) + { + return 0; + } + } + if( n == 0 ) return 0; @@ -452,7 +472,13 @@ void history_add( const wchar_t *str ) ll_node_t *old_node; if( !is_loaded ) - history_load(); + { + if( history_load() ) + { + return; + } + } + if( wcslen( str ) == 0 ) return; @@ -509,7 +535,13 @@ static int history_test( const wchar_t *needle, const wchar_t *haystack ) const wchar_t *history_prev_match( const wchar_t *str ) { if( !is_loaded ) - history_load(); + { + if( history_load() ) + { + return 0; + } + } + if( history_current == 0 ) return str; @@ -533,7 +565,13 @@ const wchar_t *history_prev_match( const wchar_t *str ) const wchar_t *history_next_match( const wchar_t *str) { if( !is_loaded ) - history_load(); + { + if( history_load() ) + { + return 0; + } + } + if( history_current == 0 ) return str; @@ -571,9 +609,15 @@ wchar_t *history_get( int idx ) { ll_node_t *n; int i; + if( !is_loaded ) - history_load(); - + { + if( history_load() ) + { + return 0; + } + } + n = history_last; if( idx<0)