aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/charset.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/charset.c')
-rw-r--r--src/nvim/charset.c54
1 files changed, 34 insertions, 20 deletions
diff --git a/src/nvim/charset.c b/src/nvim/charset.c
index 32427cc3ba..b86c66c3fe 100644
--- a/src/nvim/charset.c
+++ b/src/nvim/charset.c
@@ -177,7 +177,7 @@ int buf_init_chartab(buf_T *buf, int global)
}
if (VIM_ISDIGIT(*p)) {
- c = getdigits(&p);
+ c = getdigits_int(&p);
} else if (has_mbyte) {
c = mb_ptr2char_adv(&p);
} else {
@@ -189,7 +189,7 @@ int buf_init_chartab(buf_T *buf, int global)
++p;
if (VIM_ISDIGIT(*p)) {
- c2 = getdigits(&p);
+ c2 = getdigits_int(&p);
} else if (has_mbyte) {
c2 = mb_ptr2char_adv(&p);
} else {
@@ -1676,26 +1676,41 @@ char_u* skiptowhite_esc(char_u *p) {
return p;
}
-/// Getdigits: Get a number from a string and skip over it.
+/// Get a number from a string and skip over it.
///
-/// Note: the argument is a pointer to a char_u pointer!
+/// @param[out] pp A pointer to a pointer to char_u.
+/// It will be advanced past the read number.
///
-/// @param pp
+/// @return Number read from the string.
+intmax_t getdigits(char_u **pp)
+{
+ intmax_t number = strtoimax((char *)*pp, (char **)pp, 10);
+ assert(errno != ERANGE);
+ return number;
+}
+
+/// Get an int number from a string.
///
-/// @return Number from the string.
-long getdigits(char_u **pp)
+/// A getdigits wrapper restricted to int values.
+int getdigits_int(char_u **pp)
{
- char_u *p = *pp;
- long retval = atol((char *)p);
+ intmax_t number = getdigits(pp);
+#if SIZEOF_INTMAX_T > SIZEOF_INT
+ assert(number >= INT_MIN && number <= INT_MAX);
+#endif
+ return (int)number;
+}
- if (*p == '-') {
- // skip negative sign
- ++p;
- }
- // skip to next non-digit
- p = skipdigits(p);
- *pp = p;
- return retval;
+/// Get a long number from a string.
+///
+/// A getdigits wrapper restricted to long values.
+long getdigits_long(char_u **pp)
+{
+ intmax_t number = getdigits(pp);
+#if SIZEOF_INTMAX_T > SIZEOF_LONG
+ assert(number >= LONG_MIN && number <= LONG_MAX);
+#endif
+ return (long)number;
}
/// Return TRUE if "lbuf" is empty or only contains blanks.
@@ -1838,7 +1853,7 @@ int hex2nr(int c)
return c - '0';
}
-#if defined(FEAT_TERMRESPONSE) || defined(FEAT_GUI_GTK) || defined(PROTO)
+#if defined(FEAT_TERMRESPONSE) || defined(FEAT_GUI_GTK)
/// Convert two hex characters to a byte.
/// Return -1 if one of the characters is not hex.
@@ -1855,8 +1870,7 @@ int hexhex2nr(char_u *p)
return (hex2nr(p[0]) << 4) + hex2nr(p[1]);
}
-#endif // if defined(FEAT_TERMRESPONSE) || defined(FEAT_GUI_GTK)
- // || defined(PROTO)
+#endif // if defined(FEAT_TERMRESPONSE) || defined(FEAT_GUI_GTK)
/// Return true if "str" starts with a backslash that should be removed.
/// For WIN32 this is only done when the character after the