From 60d1ac4fec07320eed6bfb1c0f4729d57b06f79e Mon Sep 17 00:00:00 2001 From: Peter Ammon Date: Sat, 14 Jan 2012 22:48:53 -0800 Subject: [PATCH] More const and signed correctness. Warnings now fit on one page! --- fishd.cpp | 2 +- path.cpp | 2 -- reader.cpp | 8 +++----- screen.cpp | 22 +++++++++++----------- tokenizer.cpp | 2 +- tokenizer.h | 2 +- util.cpp | 3 +-- wildcard.cpp | 4 ++-- 8 files changed, 20 insertions(+), 25 deletions(-) diff --git a/fishd.cpp b/fishd.cpp index 658aa5319..cd38cfdf9 100644 --- a/fishd.cpp +++ b/fishd.cpp @@ -390,7 +390,7 @@ static void daemonize() /** Get environment variable value. The resulting string needs to be free'd. */ -static wchar_t *fishd_env_get( wchar_t *key ) +static wchar_t *fishd_env_get( const wchar_t *key ) { char *nres, *nkey; wchar_t *res; diff --git a/path.cpp b/path.cpp index ef4b212ed..53c4274dd 100644 --- a/path.cpp +++ b/path.cpp @@ -130,8 +130,6 @@ bool path_get_path_string(const wcstring &cmd_str, wcstring &output, const env_v wchar_t *path_get_path( void *context, const wchar_t *cmd ) { - const wchar_t *path; - int err = ENOENT; CHECK( cmd, 0 ); diff --git a/reader.cpp b/reader.cpp index da41d3a4c..d4d2d16a4 100644 --- a/reader.cpp +++ b/reader.cpp @@ -464,7 +464,7 @@ static void reader_kill( wchar_t *begin, int length, int mode, int newv ) free( old ); } - if( data->buff_pos > (begin-data->buff) ) + if( data->buff_pos > (size_t)(begin-data->buff) ) { data->buff_pos = maxi( begin-data->buff, data->buff_pos-length ); } @@ -1292,9 +1292,7 @@ static void reader_flash() { struct timespec pollint; - int i; - - for( i=0; ibuff_pos; i++ ) + for( size_t i=0; ibuff_pos; i++ ) { data->color[i] = HIGHLIGHT_SEARCH_MATCH<<16; } @@ -1976,7 +1974,7 @@ static void handle_token_history( int forward, int reset ) */ static void move_word( int dir, int erase, int newv ) { - int end_buff_pos=data->buff_pos; + size_t end_buff_pos=data->buff_pos; int step = dir?1:-1; /* diff --git a/screen.cpp b/screen.cpp index eb8bcc827..9e785d510 100644 --- a/screen.cpp +++ b/screen.cpp @@ -109,7 +109,7 @@ static int next_tab_stop( int in ) static int calc_prompt_width( const wchar_t *prompt ) { int res = 0; - int j, k; + size_t j, k; for( j=0; prompt[j]; j++ ) { @@ -118,7 +118,7 @@ static int calc_prompt_width( const wchar_t *prompt ) /* This is the start of an escape code. Try to guess it's width. */ - int l; + size_t p; int len=0; int found = 0; @@ -164,14 +164,14 @@ static int calc_prompt_width( const wchar_t *prompt ) } ; - for( l=0; l < (sizeof(esc)/sizeof(char *)) && !found; l++ ) + for( p=0; p < (sizeof(esc)/sizeof(char *)) && !found; p++ ) { - if( !esc[l] ) + if( !esc[p] ) continue; for( k=0; k<8; k++ ) { - len = try_sequence( tparm(esc[l],k), &prompt[j] ); + len = try_sequence( tparm(esc[p],k), &prompt[j] ); if( len ) { j += (len-1); @@ -181,17 +181,17 @@ static int calc_prompt_width( const wchar_t *prompt ) } } - for( l=0; l < (sizeof(esc2)/sizeof(char *)) && !found; l++ ) + for( p=0; p < (sizeof(esc2)/sizeof(char *)) && !found; p++ ) { - if( !esc2[l] ) + if( !esc2[p] ) continue; /* Test both padded and unpadded version, just to be safe. Most versions of tparm don't actually seem to do anything these days. */ - len = maxi( try_sequence( tparm(esc2[l]), &prompt[j] ), - try_sequence( esc2[l], &prompt[j] )); + len = maxi( try_sequence( tparm(esc2[p]), &prompt[j] ), + try_sequence( esc2[p], &prompt[j] )); if( len ) { @@ -590,7 +590,7 @@ static void s_write_str( buffer_t *b, const wchar_t *s ) */ static void s_update( screen_t *scr, const wchar_t *prompt ) { - int i, j, k; + size_t i, j; int prompt_width = calc_prompt_width( prompt ); int current_width=0; int screen_width = common_get_width(); @@ -662,7 +662,7 @@ static void s_update( screen_t *scr, const wchar_t *prompt ) s_line.create_entry(current_width).text = o; s_line.create_entry(current_width).color = o_c; - for( k=1; k= sizeof( tok_desc ) ) + if( type < 0 || (size_t)type >= sizeof( tok_desc ) ) { return _(L"Invalid token type"); } diff --git a/tokenizer.h b/tokenizer.h index 3954cc481..ad683d7e5 100644 --- a/tokenizer.h +++ b/tokenizer.h @@ -74,7 +74,7 @@ typedef struct /** Type of last token*/ int last_type; /** Length of last token*/ - int last_len; + size_t last_len; /** Offset of last token*/ int last_pos; /** Whether there are more tokens*/ diff --git a/util.cpp b/util.cpp index 464a868bb..ef0b3cd1e 100644 --- a/util.cpp +++ b/util.cpp @@ -108,7 +108,6 @@ void hash_init2( hash_table_t *h, int (*compare_func)(void *key1, void *key2), size_t capacity) { - int i; size_t sz = 32; while( sz < (capacity*4/3) ) sz*=2; @@ -127,7 +126,7 @@ void hash_init2( hash_table_t *h, } h->size = sz; - for( i=0; i< sz; i++ ) + for( size_t i=0; i< sz; i++ ) h->arr[i].key = 0; h->count=0; h->hash_func = hash_func; diff --git a/wildcard.cpp b/wildcard.cpp index 416af60f8..219a9c0dc 100644 --- a/wildcard.cpp +++ b/wildcard.cpp @@ -1087,10 +1087,10 @@ static int wildcard_expand_internal( const wchar_t *wc, */ if( whole_match ) { - wchar_t *new_wc = L""; + const wchar_t *new_wc = L""; if( wc_end ) { - new_wc=const_cast(wc_end+1); + new_wc=wc_end+1; /* Accept multiple '/' as a single direcotry separator */