diff options
-rw-r--r-- | builtin_set.c | 9 | ||||
-rw-r--r-- | expand.c | 8 | ||||
-rw-r--r-- | history.c | 10 | ||||
-rw-r--r-- | signal.c | 2 | ||||
-rw-r--r-- | util.c | 20 |
5 files changed, 38 insertions, 11 deletions
diff --git a/builtin_set.c b/builtin_set.c index 88e8fef9..084031ce 100644 --- a/builtin_set.c +++ b/builtin_set.c @@ -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; @@ -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 ) ) @@ -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; } @@ -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; @@ -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; |