Skip to content

Commit

Permalink
Check for errors during string to integer conversion in various places
Browse files Browse the repository at this point in the history
darcs-hash:20070109032005-ac50b-29514c9c8c19c70b7cfe7670a5c74899f316931f.gz
  • Loading branch information
liljencrantz committed Jan 9, 2007
1 parent 602eac8 commit b70092e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 11 deletions.
9 changes: 7 additions & 2 deletions builtin_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions expand.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) )
Expand Down
10 changes: 7 additions & 3 deletions history.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 17 additions & 3 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit b70092e

Please sign in to comment.