aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--builtin.cpp18
-rw-r--r--complete.cpp12
-rw-r--r--expand.cpp18
-rw-r--r--highlight.cpp4
-rw-r--r--parser.cpp8
-rw-r--r--wutil.cpp16
-rw-r--r--wutil.h3
7 files changed, 45 insertions, 34 deletions
diff --git a/builtin.cpp b/builtin.cpp
index 04e3f134..c4b36ed6 100644
--- a/builtin.cpp
+++ b/builtin.cpp
@@ -1692,7 +1692,7 @@ static int builtin_function( parser_t &parser, wchar_t **argv )
else
{
errno = 0;
- pid = (pid_t)wcstol( woptarg, &end, 10 );
+ pid = fish_wcstoi( woptarg, &end, 10 );
if( errno || !end || *end )
{
append_format(stderr_buffer,
@@ -2225,15 +2225,15 @@ static int builtin_read( parser_t &parser, wchar_t **argv )
break;
}
- int sz = mbrtowc( &res, &b, 1, &state );
+ size_t sz = mbrtowc( &res, &b, 1, &state );
switch( sz )
{
- case -1:
+ case (size_t)(-1):
memset (&state, '\0', sizeof (state));
break;
- case -2:
+ case (size_t)(-2):
break;
case 0:
eof=1;
@@ -2960,7 +2960,7 @@ static int builtin_fg( parser_t &parser, wchar_t **argv )
int found_job = 0;
errno = 0;
- pid = wcstol( argv[1], &endptr, 10 );
+ pid = fish_wcstoi( argv[1], &endptr, 10 );
if( !( *endptr || errno ) )
{
j = job_get_from_pid( pid );
@@ -2992,7 +2992,7 @@ static int builtin_fg( parser_t &parser, wchar_t **argv )
wchar_t *end;
int pid;
errno = 0;
- pid = abs(wcstol( argv[1], &end, 10 ));
+ pid = abs(fish_wcstoi( argv[1], &end, 10 ));
if( *end || errno )
{
@@ -3142,7 +3142,7 @@ static int builtin_bg( parser_t &parser, wchar_t **argv )
for( i=1; argv[i]; i++ )
{
errno=0;
- pid = (int)wcstol( argv[i], &end, 10 );
+ pid = fish_wcstoi( argv[i], &end, 10 );
if( errno || pid < 0 || *end || !job_get_from_pid( pid ) )
{
append_format(stderr_buffer,
@@ -3158,7 +3158,7 @@ static int builtin_bg( parser_t &parser, wchar_t **argv )
{
for( i=1; !res && argv[i]; i++ )
{
- pid = (int)wcstol( argv[i], 0, 10 );
+ pid = fish_wcstoi( argv[i], 0, 10 );
res |= send_to_bg( parser, job_get_from_pid( pid ), *argv);
}
}
@@ -3497,7 +3497,7 @@ static int builtin_return( parser_t &parser, wchar_t **argv )
{
wchar_t *end;
errno = 0;
- status = wcstol(argv[1],&end,10);
+ status = fish_wcstoi(argv[1],&end,10);
if( errno || *end != 0)
{
append_format(stderr_buffer,
diff --git a/complete.cpp b/complete.cpp
index df95ae58..e2bb336b 100644
--- a/complete.cpp
+++ b/complete.cpp
@@ -1722,14 +1722,12 @@ void complete( const wcstring &cmd, std::vector<completion_t> &comps, complete_t
completer_t completer(cmd, type);
const wchar_t *tok_begin, *tok_end, *cmdsubst_begin, *cmdsubst_end, *prev_begin, *prev_end;
- wcstring buff;
tokenizer tok;
const wchar_t *current_token=0, *prev_token=0;
wcstring current_command;
int on_command=0;
- int pos;
+ size_t pos;
bool done=false;
- int cursor_pos;
int use_command = 1;
int use_function = 1;
int use_builtin = 1;
@@ -1737,7 +1735,7 @@ void complete( const wcstring &cmd, std::vector<completion_t> &comps, complete_t
// debug( 1, L"Complete '%ls'", cmd );
- cursor_pos = cmd.size();
+ size_t cursor_pos = cmd.size();
const wchar_t *cmd_cstr = cmd.c_str();
parse_util_cmdsubst_extent( cmd_cstr, cursor_pos, &cmdsubst_begin, &cmdsubst_end );
@@ -1762,7 +1760,7 @@ void complete( const wcstring &cmd, std::vector<completion_t> &comps, complete_t
{
pos = cursor_pos-(cmdsubst_begin-cmd_cstr);
- buff = wcstring( cmdsubst_begin, cmdsubst_end-cmdsubst_begin );
+ wcstring buff = wcstring( cmdsubst_begin, cmdsubst_end-cmdsubst_begin );
int had_cmd=0;
int end_loop=0;
@@ -1805,11 +1803,9 @@ void complete( const wcstring &cmd, std::vector<completion_t> &comps, complete_t
if( !is_ddash ||
( (use_command && use_function && use_builtin ) ) )
{
- int token_end;
-
current_command = ncmd;
- token_end = tok_get_pos( &tok ) + ncmd.size();
+ size_t token_end = tok_get_pos( &tok ) + ncmd.size();
on_command = (pos <= token_end );
had_cmd=1;
diff --git a/expand.cpp b/expand.cpp
index f0f3c7fc..9ba0bdb6 100644
--- a/expand.cpp
+++ b/expand.cpp
@@ -266,7 +266,7 @@ static int iswnumeric( const wchar_t *n )
static bool match_pid( const wcstring &cmd,
const wchar_t *proc,
int flags,
- int *offset)
+ size_t *offset)
{
/* Test for a direct match. If the proc string is empty (e.g. the user tries to complete against %), then return an offset pointing at the base command. That ensures that you don't see a bunch of dumb paths when completing against all processes. */
if( proc[0] != L'\0' && wcsncmp( cmd.c_str(), proc, wcslen( proc ) ) == 0 )
@@ -489,7 +489,7 @@ bool process_iterator_t::next_process(wcstring *out_str, pid_t *out_pid)
continue;
/* remember the pid */
- pid = (long)wcstol(name.c_str(), NULL, 10);
+ pid = fish_wcstoi(name.c_str(), NULL, 10);
/* the 'cmdline' file exists, it should contain the commandline */
FILE *cmdfile;
@@ -604,7 +604,7 @@ static int find_process( const wchar_t *proc,
wchar_t *end;
errno = 0;
- jid = wcstol( proc, &end, 10 );
+ jid = fish_wcstoi( proc, &end, 10 );
if( jid > 0 && !errno && !*end )
{
j = job_get( jid );
@@ -624,11 +624,11 @@ static int find_process( const wchar_t *proc,
job_iterator_t jobs;
while ((j = jobs.next()))
{
- int offset;
if( j->command_is_empty() )
continue;
-
+
+ size_t offset;
if( match_pid( j->command(), proc, flags, &offset ) )
{
if( flags & ACCEPT_INCOMPLETE )
@@ -659,11 +659,10 @@ static int find_process( const wchar_t *proc,
continue;
for( p=j->first_process; p; p=p->next )
{
- int offset;
-
if( p->actual_cmd.empty() )
continue;
-
+
+ size_t offset;
if( match_pid( p->actual_cmd, proc, flags, &offset ) )
{
if( flags & ACCEPT_INCOMPLETE )
@@ -696,8 +695,7 @@ static int find_process( const wchar_t *proc,
process_iterator_t iterator;
while (iterator.next_process(&process_name, &process_pid))
{
- int offset;
-
+ size_t offset;
if( match_pid( process_name, proc, flags, &offset ) )
{
if( flags & ACCEPT_INCOMPLETE )
diff --git a/highlight.cpp b/highlight.cpp
index 3cf05435..1d58d702 100644
--- a/highlight.cpp
+++ b/highlight.cpp
@@ -565,7 +565,7 @@ static void highlight_param( const wcstring &buffstr, std::vector<int> &colors,
{
if( c == L'\\' )
{
- int start_pos = in_pos;
+ size_t start_pos = in_pos;
switch( buff[++in_pos] )
{
case '\\':
@@ -609,7 +609,7 @@ static void highlight_param( const wcstring &buffstr, std::vector<int> &colors,
case '\\':
{
- int start_pos = in_pos;
+ size_t start_pos = in_pos;
switch( buff[++in_pos] )
{
case L'\0':
diff --git a/parser.cpp b/parser.cpp
index 6d4e6f08..3a455132 100644
--- a/parser.cpp
+++ b/parser.cpp
@@ -1343,7 +1343,7 @@ void parser_t::parse_job_argument_list( process_t *p,
}
errno = 0;
- p->pipe_write_fd = wcstol( tok_last( tok ), &end, 10 );
+ p->pipe_write_fd = fish_wcstoi( tok_last( tok ), &end, 10 );
if( p->pipe_write_fd < 0 || errno || *end )
{
error( SYNTAX_ERROR,
@@ -1504,7 +1504,7 @@ void parser_t::parse_job_argument_list( process_t *p,
new_io.reset(new io_data_t);
errno = 0;
- new_io->fd = wcstol( tok_last( tok ),
+ new_io->fd = fish_wcstoi( tok_last( tok ),
&end,
10 );
if( new_io->fd < 0 || errno || *end )
@@ -1594,9 +1594,7 @@ void parser_t::parse_job_argument_list( process_t *p,
new_io->io_mode = IO_FD;
errno = 0;
- new_io->param1.old_fd = wcstol( target.c_str(),
- &end,
- 10 );
+ new_io->param1.old_fd = fish_wcstoi( target.c_str(), &end, 10 );
if( ( new_io->param1.old_fd < 0 ) ||
errno || *end )
diff --git a/wutil.cpp b/wutil.cpp
index f8c0caa1..661c4e93 100644
--- a/wutil.cpp
+++ b/wutil.cpp
@@ -423,3 +423,19 @@ int wrename( const wcstring &old, const wcstring &newv )
cstring new_narrow =wcs2string(newv);
return rename( old_narrow.c_str(), new_narrow.c_str() );
}
+
+int fish_wcstoi(const wchar_t *str, wchar_t ** endptr, int base)
+{
+ long ret = wcstol(str, endptr, base);
+ if (ret > INT_MAX)
+ {
+ ret = INT_MAX;
+ errno = ERANGE;
+ }
+ else if (ret < INT_MIN)
+ {
+ ret = INT_MIN;
+ errno = ERANGE;
+ }
+ return (int)ret;
+}
diff --git a/wutil.h b/wutil.h
index e05bd077..1b7cb308 100644
--- a/wutil.h
+++ b/wutil.h
@@ -141,4 +141,7 @@ int wmkdir( const wcstring &dir, int mode );
*/
int wrename( const wcstring &oldName, const wcstring &newName );
+/** Like wcstol(), but fails on a value outside the range of an int */
+int fish_wcstoi(const wchar_t *str, wchar_t ** endptr, int base);
+
#endif