mirror of
https://github.com/neovim/neovim.git
synced 2025-09-13 06:48:17 +00:00
rename: getdigits_safe => try_getdigits
This commit is contained in:
@@ -5078,7 +5078,7 @@ chk_modeline(
|
|||||||
} else {
|
} else {
|
||||||
e = s + 3;
|
e = s + 3;
|
||||||
}
|
}
|
||||||
if (getdigits_safe(&e, &vers) != OK) {
|
if (!try_getdigits(&e, &vers)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1601,18 +1601,18 @@ char_u* skiptowhite_esc(char_u *p) {
|
|||||||
/// It will be advanced past the read number.
|
/// It will be advanced past the read number.
|
||||||
/// @param[out] nr Number read from the string.
|
/// @param[out] nr Number read from the string.
|
||||||
///
|
///
|
||||||
/// @return OK on success, FAIL on error/overflow
|
/// @return true on success, false on error/overflow
|
||||||
int getdigits_safe(char_u **pp, intmax_t *nr)
|
bool try_getdigits(char_u **pp, intmax_t *nr)
|
||||||
{
|
{
|
||||||
errno = 0;
|
errno = 0;
|
||||||
*nr = strtoimax((char *)(*pp), (char **)pp, 10);
|
*nr = strtoimax((char *)(*pp), (char **)pp, 10);
|
||||||
|
|
||||||
if ((*nr == INTMAX_MIN || *nr == INTMAX_MAX)
|
if ((*nr == INTMAX_MIN || *nr == INTMAX_MAX)
|
||||||
&& errno == ERANGE) {
|
&& errno == ERANGE) {
|
||||||
return FAIL;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return OK;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a number from a string and skip over it.
|
/// Get a number from a string and skip over it.
|
||||||
@@ -1624,10 +1624,10 @@ int getdigits_safe(char_u **pp, intmax_t *nr)
|
|||||||
intmax_t getdigits(char_u **pp)
|
intmax_t getdigits(char_u **pp)
|
||||||
{
|
{
|
||||||
intmax_t number;
|
intmax_t number;
|
||||||
int ret = getdigits_safe(pp, &number);
|
int ok = try_getdigits(pp, &number);
|
||||||
|
|
||||||
(void)ret; // Avoid "unused variable" warning in Release build
|
(void)ok; // Avoid "unused variable" warning in Release build
|
||||||
assert(ret == OK);
|
assert(ok);
|
||||||
|
|
||||||
return number;
|
return number;
|
||||||
}
|
}
|
||||||
|
@@ -40,8 +40,8 @@ int socket_watcher_init(Loop *loop, SocketWatcher *watcher,
|
|||||||
char *port = host_end + 1;
|
char *port = host_end + 1;
|
||||||
intmax_t iport;
|
intmax_t iport;
|
||||||
|
|
||||||
int ret = getdigits_safe(&(char_u *){ (char_u *)port }, &iport);
|
int ok = try_getdigits(&(char_u *){ (char_u *)port }, &iport);
|
||||||
if (ret == FAIL || iport < 0 || iport > UINT16_MAX) {
|
if (!ok || iport < 0 || iport > UINT16_MAX) {
|
||||||
ELOG("Invalid port: %s", port);
|
ELOG("Invalid port: %s", port);
|
||||||
return UV_EINVAL;
|
return UV_EINVAL;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user