mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 21:44:16 +00:00
Check for errors during string to integer conversion in various places
darcs-hash:20070109032005-ac50b-29514c9c8c19c70b7cfe7670a5c74899f316931f.gz
This commit is contained in:
parent
602eac89c4
commit
b70092e281
5 changed files with 38 additions and 11 deletions
|
@ -232,9 +232,14 @@ static int parse_index( array_list_t *indexes,
|
|||
while (*src != L']')
|
||||
{
|
||||
wchar_t *end;
|
||||
long l_ind = wcstol(src, &end, 10);
|
||||
|
||||
if (end == src)
|
||||
long l_ind;
|
||||
|
||||
errno = 0;
|
||||
|
||||
l_ind = wcstol(src, &end, 10);
|
||||
|
||||
if( end==src || errno )
|
||||
{
|
||||
sb_printf(sb_err, _(L"%ls: Invalid index starting at '%ls'\n"), L"set", src);
|
||||
return 0;
|
||||
|
|
8
expand.c
8
expand.c
|
@ -387,8 +387,12 @@ static int find_process( const wchar_t *proc,
|
|||
else
|
||||
{
|
||||
|
||||
int jid = wcstol( proc, 0, 10 );
|
||||
if( jid > 0 )
|
||||
int jid;
|
||||
wchar_t *end;
|
||||
|
||||
errno = 0;
|
||||
jid = wcstol( proc, &end, 10 );
|
||||
if( jid > 0 && !errno && !*end )
|
||||
{
|
||||
j = job_get( jid );
|
||||
if( (j != 0) && (j->command != 0 ) )
|
||||
|
|
10
history.c
10
history.c
|
@ -345,9 +345,13 @@ static item_t *item_get( history_mode_t *m, void *d )
|
|||
|
||||
if( *time_string )
|
||||
{
|
||||
time_t tm = (time_t)wcstol( time_string, 0, 10 );
|
||||
|
||||
if( tm && !errno )
|
||||
time_t tm;
|
||||
wchar_t *end;
|
||||
|
||||
errno = 0;
|
||||
tm = (time_t)wcstol( time_string, &end, 10 );
|
||||
|
||||
if( tm && !errno && !*end )
|
||||
{
|
||||
narrow_item.timestamp = tm;
|
||||
}
|
||||
|
|
2
signal.c
2
signal.c
|
@ -385,7 +385,7 @@ int wcs2sig( const wchar_t *str )
|
|||
}
|
||||
errno=0;
|
||||
res = wcstol( str, &end, 10 );
|
||||
if( !errno && end && !*end )
|
||||
if( !errno && res>=0 && !*end )
|
||||
return res;
|
||||
|
||||
return -1;
|
||||
|
|
20
util.c
20
util.c
|
@ -1112,9 +1112,23 @@ int wcsfilecmp( const wchar_t *a, const wchar_t *b )
|
|||
if( iswdigit( *a ) && iswdigit( *b ) )
|
||||
{
|
||||
wchar_t *aend, *bend;
|
||||
long al = wcstol( a, &aend, 10 );
|
||||
long bl = wcstol( b, &bend, 10 );
|
||||
int diff = al - bl;
|
||||
long al;
|
||||
long bl;
|
||||
int diff;
|
||||
|
||||
errno = 0;
|
||||
al = wcstol( a, &aend, 10 );
|
||||
bl = wcstol( b, &bend, 10 );
|
||||
|
||||
if( errno )
|
||||
{
|
||||
/*
|
||||
Huuuuuuuuge numbers - fall back to regular string comparison
|
||||
*/
|
||||
return wcscmp( a, b );
|
||||
}
|
||||
|
||||
diff = al - bl;
|
||||
if( diff )
|
||||
return diff>0?2:-2;
|
||||
|
||||
|
|
Loading…
Reference in a new issue