mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-03-23 11:15:14 +08:00
Improve const and signed/unsigned correctness
This commit is contained in:
parent
203c749e6c
commit
9b133a978d
@ -1866,7 +1866,7 @@ void bugreport()
|
||||
void sb_format_size( string_buffer_t *sb,
|
||||
long long sz )
|
||||
{
|
||||
wchar_t *sz_name[]=
|
||||
const wchar_t *sz_name[]=
|
||||
{
|
||||
L"kB", L"MB", L"GB", L"TB", L"PB", L"EB", L"ZB", L"YB", 0
|
||||
}
|
||||
|
7
exec.cpp
7
exec.cpp
@ -543,8 +543,9 @@ static void launch_process( process_t *p )
|
||||
count++;
|
||||
|
||||
res = (wchar_t **)malloc( sizeof(wchar_t*)*(count+2));
|
||||
|
||||
res[0] = L"/bin/sh";
|
||||
wchar_t sh_command[] = L"/bin/sh";
|
||||
|
||||
res[0] = sh_command;
|
||||
res[1] = p->actual_cmd;
|
||||
|
||||
for( i=1; p->argv[i]; i++ ){
|
||||
@ -553,7 +554,7 @@ static void launch_process( process_t *p )
|
||||
|
||||
res[i+1] = 0;
|
||||
p->argv = res;
|
||||
p->actual_cmd = L"/bin/sh";
|
||||
p->actual_cmd = sh_command;
|
||||
|
||||
res_real = wcsv2strv( (const wchar_t **) res);
|
||||
|
||||
|
4
fish.cpp
4
fish.cpp
@ -110,7 +110,7 @@ static int read_init()
|
||||
Parse the argument list, return the index of the first non-switch
|
||||
arguments.
|
||||
*/
|
||||
static int fish_parse_opt( int argc, char **argv, char **cmd_ptr )
|
||||
static int fish_parse_opt( int argc, char **argv, const char **cmd_ptr )
|
||||
{
|
||||
int my_optind;
|
||||
int force_interactive=0;
|
||||
@ -280,7 +280,7 @@ int main( int argc, char **argv )
|
||||
{
|
||||
struct stat tmp;
|
||||
int res=1;
|
||||
char *cmd=0;
|
||||
const char *cmd=0;
|
||||
int my_optind=0;
|
||||
|
||||
halloc_util_init();
|
||||
|
@ -1039,7 +1039,7 @@ static void highlight_universal_internal( const wchar_t * buff,
|
||||
int pos )
|
||||
{
|
||||
|
||||
if( (pos >= 0) && (pos < wcslen(buff)) )
|
||||
if( (pos >= 0) && ((size_t)pos < wcslen(buff)) )
|
||||
{
|
||||
|
||||
/*
|
||||
|
@ -73,7 +73,7 @@
|
||||
\param pos the cursor position. Used for quote matching, etc.
|
||||
\param error a list in which a description of each error will be inserted. May be 0, in whcich case no error descriptions will be generated.
|
||||
*/
|
||||
void highlight_shell( const wchar_t *, int *, int, array_list_t *, const env_vars &vars );
|
||||
void highlight_shell( const wchar_t *buff, int *color, int pos, array_list_t *error, const env_vars &vars );
|
||||
|
||||
/**
|
||||
Perform syntax highlighting for the text in buff. Matching quotes and paranthesis are highlighted. The result is
|
||||
@ -85,7 +85,7 @@ void highlight_shell( const wchar_t *, int *, int, array_list_t *, const env_var
|
||||
\param pos the cursor position. Used for quote matching, etc.
|
||||
\param error a list in which a description of each error will be inserted. May be 0, in whcich case no error descriptions will be generated.
|
||||
*/
|
||||
void highlight_universal( const wchar_t *, int *, int, array_list_t *, const env_vars &vars );
|
||||
void highlight_universal( const wchar_t *buff, int *color, int pos, array_list_t *error, const env_vars &vars );
|
||||
|
||||
/**
|
||||
Translate from HIGHLIGHT_* to FISH_COLOR_* according to environment
|
||||
|
@ -295,7 +295,7 @@ static char *file_exists( const char *dir, const char *in )
|
||||
\param all If zero, then stop after the first filename.
|
||||
\return The number of filenames added to the list.
|
||||
*/
|
||||
static int append_filenames( array_list_t *list, char *f, int all )
|
||||
static int append_filenames( array_list_t *list, const char *f, int all )
|
||||
{
|
||||
int prev_count = al_get_count( list );
|
||||
char *result;
|
||||
|
17
output.cpp
17
output.cpp
@ -382,7 +382,7 @@ int writembs_internal( char *str )
|
||||
int writech( wint_t ch )
|
||||
{
|
||||
mbstate_t state;
|
||||
int i;
|
||||
size_t i;
|
||||
char buff[MB_LEN_MAX+1];
|
||||
size_t bytes;
|
||||
|
||||
@ -548,20 +548,20 @@ int write_escaped_str( const wchar_t *str, int max_len )
|
||||
|
||||
int output_color_code( const wchar_t *val )
|
||||
{
|
||||
int j, i, color=FISH_COLOR_NORMAL;
|
||||
array_list_t el;
|
||||
size_t i;
|
||||
int color=FISH_COLOR_NORMAL;
|
||||
int is_bold=0;
|
||||
int is_underline=0;
|
||||
|
||||
if( !val )
|
||||
return FISH_COLOR_NORMAL;
|
||||
|
||||
al_init( &el );
|
||||
tokenize_variable_array( val, &el );
|
||||
wcstring_list_t el;
|
||||
tokenize_variable_array2( val, el );
|
||||
|
||||
for( j=0; j<al_get_count( &el ); j++ )
|
||||
for(size_t j=0; j < el.size(); j++ )
|
||||
{
|
||||
wchar_t *next = (wchar_t *)al_get( &el, j );
|
||||
const wchar_t *next = el.at(j).c_str();
|
||||
|
||||
is_bold |= (wcsncmp( next, L"--bold", wcslen(next) ) == 0 ) && wcslen(next)>=3;
|
||||
is_bold |= wcscmp( next, L"-o" ) == 0;
|
||||
@ -580,9 +580,6 @@ int output_color_code( const wchar_t *val )
|
||||
|
||||
}
|
||||
|
||||
al_foreach( &el, &free );
|
||||
al_destroy( &el );
|
||||
|
||||
return color | (is_bold?FISH_COLOR_BOLD:0) | (is_underline?FISH_COLOR_UNDERLINE:0);
|
||||
|
||||
}
|
||||
|
2
proc.h
2
proc.h
@ -240,7 +240,7 @@ typedef struct job
|
||||
job. It is used for displaying messages about job status
|
||||
on the terminal.
|
||||
*/
|
||||
wchar_t *command;
|
||||
const wchar_t *command;
|
||||
|
||||
/**
|
||||
A linked list of all the processes in this job.
|
||||
|
@ -63,7 +63,7 @@
|
||||
#define _(string) (string)
|
||||
#endif
|
||||
|
||||
char *col[]=
|
||||
const char *col[]=
|
||||
{
|
||||
"black",
|
||||
"red",
|
||||
@ -79,7 +79,7 @@ char *col[]=
|
||||
}
|
||||
;
|
||||
|
||||
int col_idx[]=
|
||||
const int col_idx[]=
|
||||
{
|
||||
0,
|
||||
1,
|
||||
@ -108,7 +108,7 @@ int translate_color( char *str )
|
||||
|
||||
if( *endptr || color<0 || errno )
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
color = -1;
|
||||
for( i=0; i<COLORS; i++ )
|
||||
{
|
||||
@ -126,7 +126,7 @@ int translate_color( char *str )
|
||||
|
||||
void print_colors()
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
for( i=0; i<COLORS; i++ )
|
||||
{
|
||||
printf( "%s\n", col[i] );
|
||||
|
2
util.cpp
2
util.cpp
@ -751,7 +751,7 @@ static anything_t al_get_generic( array_list_t *l, int pos )
|
||||
anything_t res;
|
||||
res.ptr_val=0;
|
||||
|
||||
if( (pos >= 0) && (pos < l->pos) )
|
||||
if( (pos >= 0) && ((size_t)pos < l->pos) )
|
||||
res = l->arr[pos];
|
||||
|
||||
return res;
|
||||
|
@ -315,7 +315,7 @@ _xdg_mime_magic_parse_magic_line (FILE *magic_file,
|
||||
int c;
|
||||
int end_of_file;
|
||||
int indent = 0;
|
||||
int bytes_read;
|
||||
size_t bytes_read;
|
||||
|
||||
assert (magic_file != NULL);
|
||||
|
||||
@ -460,7 +460,7 @@ _xdg_mime_magic_parse_magic_line (FILE *magic_file,
|
||||
_xdg_mime_magic_matchlet_free (matchlet);
|
||||
return XDG_MIME_MAGIC_EOF;
|
||||
}
|
||||
if (matchlet->range_length == -1)
|
||||
if (matchlet->range_length == (unsigned int)-1)
|
||||
{
|
||||
_xdg_mime_magic_matchlet_free (matchlet);
|
||||
return XDG_MIME_MAGIC_ERROR;
|
||||
@ -474,7 +474,7 @@ _xdg_mime_magic_parse_magic_line (FILE *magic_file,
|
||||
/* We clean up the matchlet, byte swapping if needed */
|
||||
if (matchlet->word_size > 1)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
if (matchlet->value_length % matchlet->word_size != 0)
|
||||
{
|
||||
_xdg_mime_magic_matchlet_free (matchlet);
|
||||
@ -519,7 +519,7 @@ _xdg_mime_magic_matchlet_compare_to_data (XdgMimeMagicMatchlet *matchlet,
|
||||
const void *data,
|
||||
size_t len)
|
||||
{
|
||||
int i, j;
|
||||
size_t i, j;
|
||||
|
||||
for (i = matchlet->offset; i <= matchlet->offset + matchlet->range_length; i++)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user