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.c45
1 files changed, 28 insertions, 17 deletions
diff --git a/src/nvim/charset.c b/src/nvim/charset.c
index 32427cc3ba..8781e389ed 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,37 @@ 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);
+ assert(number >= INT_MIN && number <= INT_MAX);
+ 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);
+ assert(number >= LONG_MIN && number <= LONG_MAX);
+ return (long)number;
}
/// Return TRUE if "lbuf" is empty or only contains blanks.