From 84729c4dfa6d16cf81aa23c249d0ffb030549e08 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 5 Aug 2012 13:24:33 -0700 Subject: Additional warnings cleanup, effective C++ violations, dead code removal --- FishsFish.xcodeproj/project.pbxproj | 2 - autoload.cpp | 5 ++- builtin.cpp | 4 +- color.cpp | 13 +++--- common.cpp | 80 ++++++------------------------------- common.h | 22 ++++++---- complete.h | 2 +- env_universal_common.cpp | 2 +- event.h | 2 +- fallback.cpp | 2 +- fish_indent.cpp | 3 +- fish_pager.cpp | 4 +- fishd.cpp | 5 ++- io.h | 12 +++++- osx/config.h | 5 +++ parse_util.cpp | 6 +-- proc.h | 13 +++--- reader.cpp | 2 +- 18 files changed, 79 insertions(+), 105 deletions(-) diff --git a/FishsFish.xcodeproj/project.pbxproj b/FishsFish.xcodeproj/project.pbxproj index b9aad777..320528b5 100644 --- a/FishsFish.xcodeproj/project.pbxproj +++ b/FishsFish.xcodeproj/project.pbxproj @@ -1014,7 +1014,6 @@ "SYSCONFDIR=L\\\"/usr/local/etc\\\"", ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_VERSION = com.apple.compilers.llvm.clang.1_0; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; @@ -1040,7 +1039,6 @@ "DATADIR=L\\\"/usr/local/share\\\"", "SYSCONFDIR=L\\\"/usr/local/etc\\\"", ); - GCC_VERSION = com.apple.compilers.llvm.clang.1_0; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; diff --git a/autoload.cpp b/autoload.cpp index 6ac3976f..8f77f74f 100644 --- a/autoload.cpp +++ b/autoload.cpp @@ -39,9 +39,12 @@ file_access_attempt_t access_file(const wcstring &path, int mode) { } autoload_t::autoload_t(const wcstring &env_var_name_var, const builtin_script_t * const scripts, size_t script_count) : + lock(), env_var_name(env_var_name_var), builtin_scripts(scripts), - builtin_script_count(script_count) + builtin_script_count(script_count), + last_path(), + is_loading_set() { pthread_mutex_init(&lock, NULL); } diff --git a/builtin.cpp b/builtin.cpp index 30a69b73..f910486c 100644 --- a/builtin.cpp +++ b/builtin.cpp @@ -1808,7 +1808,7 @@ static int builtin_function( parser_t &parser, wchar_t **argv ) if( res ) { size_t i; - int chars=0; + size_t chars=0; builtin_print_help( parser, argv[0], stderr_buffer ); const wchar_t *cfa = _( L"Current functions are: " ); @@ -1941,7 +1941,7 @@ static int builtin_random( parser_t &parser, wchar_t **argv ) } lrand48_r( &seed_buffer, &res ); - append_format(stdout_buffer, L"%d\n", abs(res%32767) ); + append_format(stdout_buffer, L"%ld\n", labs(res%32767) ); break; } diff --git a/color.cpp b/color.cpp index 99dcf1e9..3b7baa89 100644 --- a/color.cpp +++ b/color.cpp @@ -41,6 +41,12 @@ static int parse_hex_digit(wchar_t x) { } } +static unsigned long squared_difference(long p1, long p2) +{ + unsigned long diff = (unsigned long)labs(p1 - p2); + return diff * diff; +} + static unsigned char convert_color(const unsigned char rgb[3], const uint32_t *colors, size_t color_count) { long r = rgb[0], g = rgb[1], b = rgb[2]; unsigned long best_distance = (unsigned long)(-1); @@ -48,10 +54,7 @@ static unsigned char convert_color(const unsigned char rgb[3], const uint32_t *c for (unsigned char idx = 0; idx < color_count; idx++) { uint32_t color = colors[idx]; long test_r = (color >> 16) & 0xFF, test_g = (color >> 8) & 0xFF, test_b = (color >> 0) & 0xFF; - unsigned long distance = 0; - distance += (r - test_r) * (r - test_r); - distance += (g - test_g) * (g - test_g); - distance += (b - test_b) * (b - test_b); + unsigned long distance = squared_difference(r, test_r) + squared_difference(g, test_g) + squared_difference(b, test_b); if (distance <= best_distance) { best_index = idx; best_distance = distance; @@ -221,7 +224,7 @@ unsigned char rgb_color_t::to_name_index() const { return term8_color_for_rgb(data.rgb); } else { /* This is an error */ - return -1; + return (unsigned char)(-1); } } diff --git a/common.cpp b/common.cpp index 5ca7df5f..53ab5541 100644 --- a/common.cpp +++ b/common.cpp @@ -161,64 +161,6 @@ int fgetws2(wcstring *s, FILE *f) } } -int fgetws2( wchar_t **b, int *len, FILE *f ) -{ - int i=0; - wint_t c; - - wchar_t *buff = *b; - - while( 1 ) - { - /* Reallocate the buffer if necessary */ - if( i+1 >= *len ) - { - int new_len = maxi( 128, (*len)*2); - buff = (wchar_t *)realloc( buff, sizeof(wchar_t)*new_len ); - if( buff == 0 ) - { - DIE_MEM(); - } - else - { - *len = new_len; - *b = buff; - } - } - - errno=0; - - c = getwc( f ); - - if( errno == EILSEQ ) - { - continue; - } - -//fwprintf( stderr, L"b\n" ); - - switch( c ) - { - /* End of line */ - case WEOF: - case L'\n': - case L'\0': - buff[i]=L'\0'; - return i; - /* Ignore carriage returns */ - case L'\r': - break; - - default: - buff[i++]=c; - break; - } - - - } - -} - wchar_t *str2wcs( const char *in ) { wchar_t *out; @@ -253,8 +195,8 @@ wcstring str2wcstring( const std::string &in ) wchar_t *str2wcs_internal( const char *in, wchar_t *out ) { size_t res=0; - int in_pos=0; - int out_pos = 0; + size_t in_pos=0; + size_t out_pos = 0; mbstate_t state; size_t len; @@ -354,8 +296,8 @@ std::string wcs2string(const wcstring &input) char *wcs2str_internal( const wchar_t *in, char *out ) { size_t res=0; - int in_pos=0; - int out_pos = 0; + size_t in_pos=0; + size_t out_pos = 0; mbstate_t state; CHECK( in, 0 ); @@ -396,8 +338,7 @@ char *wcs2str_internal( const wchar_t *in, char *out ) char **wcsv2strv( const wchar_t * const *in ) { - int count =0; - int i; + size_t i, count = 0; while( in[count] != 0 ) count++; @@ -656,7 +597,7 @@ ssize_t write_loop(int fd, const char *buff, size_t count) break; } } - return out_cum; + return (ssize_t)out_cum; } ssize_t read_loop(int fd, void *buff, size_t count) @@ -1807,7 +1748,7 @@ wcstring format_size(long long sz) { if( sz < (1024*1024) || !sz_name[i+1] ) { - int isz = sz/1024; + long isz = ((long)sz)/1024; if( isz > 9 ) result.append( format_string( L"%d%ls", isz, sz_name[i] )); else @@ -2054,7 +1995,12 @@ scoped_lock::~scoped_lock() { if (locked) this->unlock(); } -wcstokenizer::wcstokenizer(const wcstring &s, const wcstring &separator) : sep(separator) { +wcstokenizer::wcstokenizer(const wcstring &s, const wcstring &separator) : + buffer(), + str(), + state(), + sep(separator) +{ buffer = wcsdup(s.c_str()); str = buffer; state = NULL; diff --git a/common.h b/common.h index cd6bd9a0..05c795bb 100644 --- a/common.h +++ b/common.h @@ -192,19 +192,14 @@ void show_stackframe(); /** - Read a line from the stream f into the buffer buff of length len. If - buff is to small, it will be reallocated, and both buff and len will - be updated to reflect this. Returns the number of bytes read or -1 - on failiure. + Read a line from the stream f into the string. Returns + the number of bytes read or -1 on failiure. If the carriage return character is encountered, it is ignored. fgetws() considers the line to end if reading the file results in either a newline (L'\n') character, the null (L'\\0') character or the end of file (WEOF) character. */ -int fgetws2( wchar_t **buff, int *len, FILE *f ); - -/** Like fgetws2, but reads into a string */ int fgetws2(wcstring *s, FILE *f); /** @@ -454,6 +449,10 @@ class narrow_string_rep_t { private: const char *str; + /* No copying */ + narrow_string_rep_t &operator=(const narrow_string_rep_t &); + narrow_string_rep_t(const narrow_string_rep_t &x); + public: ~narrow_string_rep_t() { free((void *)str); @@ -477,6 +476,11 @@ bool is_forked_child(); class scoped_lock { pthread_mutex_t *lock_obj; bool locked; + + /* No copying */ + scoped_lock &operator=(const scoped_lock &); + scoped_lock(const scoped_lock &); + public: void lock(void); void unlock(void); @@ -489,6 +493,10 @@ class wcstokenizer { wchar_t *buffer, *str, *state; const wcstring sep; + /* No copying */ + wcstokenizer &operator=(const wcstokenizer &); + wcstokenizer(const wcstokenizer &); + public: wcstokenizer(const wcstring &s, const wcstring &separator); bool next(wcstring &result); diff --git a/complete.h b/complete.h index a5a6f7a7..ddf60171 100644 --- a/complete.h +++ b/complete.h @@ -109,7 +109,7 @@ class completion_t private: /* No public default constructor */ - completion_t(){ } + completion_t(); public: /** diff --git a/env_universal_common.cpp b/env_universal_common.cpp index 26f986c8..f476e1ba 100644 --- a/env_universal_common.cpp +++ b/env_universal_common.cpp @@ -95,7 +95,7 @@ typedef struct var_uni_entry { int exportv; /**< Whether the variable should be exported */ wcstring val; /**< The value of the variable */ - var_uni_entry():exportv(0) { } + var_uni_entry():exportv(0), val() { } } var_uni_entry_t; diff --git a/event.h b/event.h index c176a50a..1ba6d01d 100644 --- a/event.h +++ b/event.h @@ -85,7 +85,7 @@ struct event_t */ std::auto_ptr arguments; - event_t(int t) : type(t), param1() { } + event_t(int t) : type(t), param1(), str_param1(), function_name(), arguments() { } /** Copy constructor */ event_t(const event_t &x); diff --git a/fallback.cpp b/fallback.cpp index 473a046e..1dd96406 100644 --- a/fallback.cpp +++ b/fallback.cpp @@ -1111,7 +1111,7 @@ int lrand48_r(struct drand48_data *buffer, long int *result) int srand48_r(long int seedval, struct drand48_data *buffer) { - buffer->seed = (int)seedval; + buffer->seed = (unsigned int)seedval; return 0; } diff --git a/fish_indent.cpp b/fish_indent.cpp index 22a345b7..298d52e8 100644 --- a/fish_indent.cpp +++ b/fish_indent.cpp @@ -74,7 +74,8 @@ static void read_file( FILE *f, wcstring &b ) */ static void insert_tabs( wcstring &out, int indent ) { - out.append(indent, L'\t'); + if (indent > 0) + out.append((size_t)indent, L'\t'); } diff --git a/fish_pager.cpp b/fish_pager.cpp index 3c9392b1..7c24b5f4 100644 --- a/fish_pager.cpp +++ b/fish_pager.cpp @@ -886,7 +886,7 @@ static void join_completions( wcstring_list_t lst ) prev_idx = desc_table[desc] - 1; if( prev_idx == -1 ) { - desc_table[desc] = i+1; + desc_table[desc] = (long)(i+1); } else { @@ -951,7 +951,7 @@ static std::vector mangle_completions( wcstring_list_t &lst, const wch } - comp->comp_width += my_wcswidth(prefix)*comp->comp.size() + 2*(comp->comp.size()-1); + comp->comp_width += (int)(my_wcswidth(prefix)*comp->comp.size() + 2*(comp->comp.size()-1)); comp->desc_width = comp->desc.empty()?0:my_wcswidth( comp->desc.c_str() ); comp->pref_width = comp->comp_width + comp->desc_width + (comp->desc_width?4:0); diff --git a/fishd.cpp b/fishd.cpp index 1cd7be6f..be69ac41 100644 --- a/fishd.cpp +++ b/fishd.cpp @@ -224,8 +224,9 @@ static void sprint_rand_digits( char *str, int maxlen ) Cast to unsigned so that wrapping occurs on overflow as per ANSI C. */ (void)gettimeofday( &tv, NULL ); - srand( (unsigned int)tv.tv_sec + (unsigned int)tv.tv_usec * 1000000UL ); - max = 1 + (maxlen - 1) * (rand() / (RAND_MAX + 1.0)); + unsigned long long seed = tv.tv_sec + tv.tv_usec * 1000000ULL; + srand( (unsigned int)seed ); + max = (int)(1 + (maxlen - 1) * (rand() / (RAND_MAX + 1.0))); for( i = 0; i < max; i++ ) { str[i] = '0' + 10 * (rand() / (RAND_MAX + 1.0)); diff --git a/io.h b/io.h index 5d304cc3..49bbbafa 100644 --- a/io.h +++ b/io.h @@ -21,7 +21,7 @@ private: shared_ptr > out_buffer; /* No assignment allowed */ - void operator=(const io_data_t &rhs) { assert(0); } + void operator=(const io_data_t &rhs); public: /** Type of redirect */ @@ -88,7 +88,15 @@ public: /** Pointer to the next IO redirection */ io_data_t *next; - io_data_t() : filename_cstr(NULL), next(NULL) + io_data_t() : + out_buffer(), + io_mode(0), + fd(0), + param1(), + param2(), + filename_cstr(NULL), + is_input(0), + next(NULL) { } diff --git a/osx/config.h b/osx/config.h index 14207b37..f606d92f 100644 --- a/osx/config.h +++ b/osx/config.h @@ -1,6 +1,9 @@ /* config.h. Generated from config.h.in by configure. */ /* config.h.in. Generated from configure.ac by autoheader. */ +#ifndef FISH_CONFIG_H +#define FISH_CONFIG_H + /* Define to 1 if you have the `backtrace' function. */ #define HAVE_BACKTRACE 1 @@ -216,3 +219,5 @@ #define __warn_unused #define __sentinel #endif + +#endif diff --git a/parse_util.cpp b/parse_util.cpp index 80065a51..f523e38d 100644 --- a/parse_util.cpp +++ b/parse_util.cpp @@ -478,15 +478,15 @@ void parse_util_token_extent( const wchar_t *buff, tok_has_next( &tok ); tok_next( &tok ) ) { - int tok_begin = tok_get_pos( &tok ); - int tok_end=tok_begin; + size_t tok_begin = tok_get_pos( &tok ); + size_t tok_end = tok_begin; /* Calculate end of token */ if( tok_last_type( &tok ) == TOK_STRING ) { - tok_end +=wcslen(tok_last(&tok)); + tok_end += wcslen(tok_last(&tok)); } /* diff --git a/proc.h b/proc.h index 45648f51..b313dac5 100644 --- a/proc.h +++ b/proc.h @@ -134,15 +134,15 @@ class process_t /* narrow copy of argv0 so we don't have to convert after fork */ narrow_string_rep_t argv0_narrow; - /* No copying */ - process_t(const process_t &rhs) { } - void operator=(const process_t &rhs) { } + process_t(const process_t &rhs); + void operator=(const process_t &rhs); public: process_t() : - argv_array(), + argv_array(), + argv0_narrow(), type(0), actual_cmd(), pid(0), @@ -316,13 +316,14 @@ class job_t narrow_string_rep_t command_narrow; /* No copying */ - job_t(const job_t &rhs) : job_id(0) { } - void operator=(const job_t &) { } + job_t(const job_t &rhs); + void operator=(const job_t &); public: job_t(job_id_t jobid) : command_str(), + command_narrow(), first_process(NULL), pgid(0), tmodes(), diff --git a/reader.cpp b/reader.cpp index 39c0b984..ecf78d84 100644 --- a/reader.cpp +++ b/reader.cpp @@ -2038,7 +2038,7 @@ void set_env_cmd_duration(struct timeval *after, struct timeval *before) } else if (secs < 5400) { // 1.5 hours swprintf(buf, 16, L"%lum %lus", secs / 60, secs % 60); } else { - swprintf(buf, 16, L"%.1fh", secs / 3600.0f); + swprintf(buf, 16, L"%.1fh", secs / 3600.0); } env_set( ENV_CMD_DURATION, buf, ENV_EXPORT ); } -- cgit v1.2.3