Additional warnings cleanup, effective C++ violations, dead code removal

This commit is contained in:
ridiculousfish 2012-08-05 13:24:33 -07:00
parent 8de8877c7c
commit 84729c4dfa
18 changed files with 79 additions and 105 deletions

View file

@ -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;

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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);
}
}

View file

@ -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;

View file

@ -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);

View file

@ -109,7 +109,7 @@ class completion_t
private:
/* No public default constructor */
completion_t(){ }
completion_t();
public:
/**

View file

@ -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;

View file

@ -85,7 +85,7 @@ struct event_t
*/
std::auto_ptr<wcstring_list_t> 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);

View file

@ -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;
}

View file

@ -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');
}

View file

@ -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<comp_t *> 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);

View file

@ -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));

12
io.h
View file

@ -21,7 +21,7 @@ private:
shared_ptr<std::vector<char> > 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)
{
}

View file

@ -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

View file

@ -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));
}
/*

11
proc.h
View file

@ -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(),
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(),

View file

@ -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 );
}