mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-25 02:01:15 -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:
@@ -25,6 +25,7 @@
|
||||
#include "input_common.h"
|
||||
#include "iothread.h"
|
||||
#include "util.h"
|
||||
#include "wutil.h"
|
||||
|
||||
/// Time in milliseconds to wait for another byte to be available for reading
|
||||
/// after \x1b is read before assuming that escape key was pressed, and not an
|
||||
@@ -167,13 +168,11 @@ void update_wait_on_escape_ms() {
|
||||
return;
|
||||
}
|
||||
|
||||
wchar_t *endptr;
|
||||
long tmp = wcstol(escape_time_ms.c_str(), &endptr, 10);
|
||||
|
||||
if (*endptr != '\0' || tmp < 10 || tmp >= 5000) {
|
||||
long tmp = fish_wcstol(escape_time_ms.c_str());
|
||||
if (errno || tmp < 10 || tmp >= 5000) {
|
||||
fwprintf(stderr,
|
||||
L"ignoring fish_escape_delay_ms: value '%ls' "
|
||||
"is not an integer or is < 10 or >= 5000 ms\n",
|
||||
L"is not an integer or is < 10 or >= 5000 ms\n",
|
||||
escape_time_ms.c_str());
|
||||
} else {
|
||||
wait_on_escape_ms = (int)tmp;
|
||||
|
||||
Reference in New Issue
Block a user