mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-06 22:51:14 -03:00
improve converting strings to ints/longs
The existing code is inconsistent, and in a couple of cases wrong, about dealing with strings that are not valid ints. For example, there are locations that call wcstol() and check errno without first setting errno to zero. Normalize the code to a consistent pattern. This is mostly to deal with inconsistencies between BSD, GNU, and other UNIXes. This does make some syntax more liberal. For example `echo $PATH[1 .. 3]` is now valid due to uniformly allowing leading and trailing whitespace around numbers. Whereas prior to this change you would get a "Invalid index value" error. Contrast this with `echo $PATH[ 1.. 3 ]` which was valid and still is.
This commit is contained in:
@@ -426,12 +426,8 @@ int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv)
|
||||
|
||||
if (cursor_mode) {
|
||||
if (argc - w.woptind) {
|
||||
wchar_t *endptr;
|
||||
long new_pos;
|
||||
errno = 0;
|
||||
|
||||
new_pos = wcstol(argv[w.woptind], &endptr, 10);
|
||||
if (*endptr || errno) {
|
||||
long new_pos = fish_wcstol(argv[w.woptind]);
|
||||
if (errno) {
|
||||
streams.err.append_format(BUILTIN_ERR_NOT_NUMBER, argv[0], argv[w.woptind]);
|
||||
builtin_print_help(parser, streams, argv[0], streams.err);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user