diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-07-30 06:26:09 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-29 22:26:09 +0000 |
commit | d131c48c823c30f519506eddcaef662dad5afa43 (patch) | |
tree | 12766f0359583db32dc86e3cd28eeb45233a6342 /src | |
parent | 94d42a3e7239a4035ee4429cbd71d5b0162b8289 (diff) | |
download | rneovim-d131c48c823c30f519506eddcaef662dad5afa43.tar.gz rneovim-d131c48c823c30f519506eddcaef662dad5afa43.tar.bz2 rneovim-d131c48c823c30f519506eddcaef662dad5afa43.zip |
vim-patch:9.1.0638: E1510 may happen when formatting a message for smsg() (#29907)
Problem: E1510 may happen when formatting a message
(after 9.1.0181).
Solution: Only give E1510 when using typval. (zeertzjq)
closes: vim/vim#15391
https://github.com/vim/vim/commit/0dff31576a340b74cec81517912923c38cb28450
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/strings.c | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/src/nvim/strings.c b/src/nvim/strings.c index 0aaa100bf2..b7a87ae030 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -1005,7 +1005,7 @@ static void format_overflow_error(const char *pstart) enum { MAX_ALLOWED_STRING_WIDTH = 6400, }; -static int get_unsigned_int(const char *pstart, const char **p, unsigned *uj) +static int get_unsigned_int(const char *pstart, const char **p, unsigned *uj, bool overflow_err) { *uj = (unsigned)(**p - '0'); (*p)++; @@ -1016,8 +1016,12 @@ static int get_unsigned_int(const char *pstart, const char **p, unsigned *uj) } if (*uj > MAX_ALLOWED_STRING_WIDTH) { - format_overflow_error(pstart); - return FAIL; + if (overflow_err) { + format_overflow_error(pstart); + return FAIL; + } else { + *uj = MAX_ALLOWED_STRING_WIDTH; + } } return OK; @@ -1078,7 +1082,7 @@ static int parse_fmt_types(const char ***ap_types, int *num_posarg, const char * // Positional argument unsigned uj; - if (get_unsigned_int(pstart, &p, &uj) == FAIL) { + if (get_unsigned_int(pstart, &p, &uj, tvs != NULL) == FAIL) { goto error; } @@ -1121,7 +1125,7 @@ static int parse_fmt_types(const char ***ap_types, int *num_posarg, const char * // Positional argument field width unsigned uj; - if (get_unsigned_int(arg + 1, &p, &uj) == FAIL) { + if (get_unsigned_int(arg + 1, &p, &uj, tvs != NULL) == FAIL) { goto error; } @@ -1147,7 +1151,7 @@ static int parse_fmt_types(const char ***ap_types, int *num_posarg, const char * const char *digstart = p; unsigned uj; - if (get_unsigned_int(digstart, &p, &uj) == FAIL) { + if (get_unsigned_int(digstart, &p, &uj, tvs != NULL) == FAIL) { goto error; } @@ -1168,7 +1172,7 @@ static int parse_fmt_types(const char ***ap_types, int *num_posarg, const char * // Parse precision unsigned uj; - if (get_unsigned_int(arg + 1, &p, &uj) == FAIL) { + if (get_unsigned_int(arg + 1, &p, &uj, tvs != NULL) == FAIL) { goto error; } @@ -1195,7 +1199,7 @@ static int parse_fmt_types(const char ***ap_types, int *num_posarg, const char * const char *digstart = p; unsigned uj; - if (get_unsigned_int(digstart, &p, &uj) == FAIL) { + if (get_unsigned_int(digstart, &p, &uj, tvs != NULL) == FAIL) { goto error; } @@ -1491,7 +1495,7 @@ int vim_vsnprintf_typval(char *str, size_t str_m, const char *fmt, va_list ap_st const char *digstart = p; unsigned uj; - if (get_unsigned_int(digstart, &p, &uj) == FAIL) { + if (get_unsigned_int(digstart, &p, &uj, tvs != NULL) == FAIL) { goto error; } @@ -1533,7 +1537,7 @@ int vim_vsnprintf_typval(char *str, size_t str_m, const char *fmt, va_list ap_st // Positional argument field width unsigned uj; - if (get_unsigned_int(digstart, &p, &uj) == FAIL) { + if (get_unsigned_int(digstart, &p, &uj, tvs != NULL) == FAIL) { goto error; } @@ -1542,15 +1546,19 @@ int vim_vsnprintf_typval(char *str, size_t str_m, const char *fmt, va_list ap_st p++; } - const int j = (tvs - ? (int)tv_nr(tvs, &arg_idx) - : (skip_to_arg(ap_types, ap_start, &ap, &arg_idx, - &arg_cur, fmt), - va_arg(ap, int))); + int j = (tvs + ? (int)tv_nr(tvs, &arg_idx) + : (skip_to_arg(ap_types, ap_start, &ap, &arg_idx, + &arg_cur, fmt), + va_arg(ap, int))); if (j > MAX_ALLOWED_STRING_WIDTH) { - format_overflow_error(digstart); - goto error; + if (tvs != NULL) { + format_overflow_error(digstart); + goto error; + } else { + j = MAX_ALLOWED_STRING_WIDTH; + } } if (j >= 0) { @@ -1565,12 +1573,7 @@ int vim_vsnprintf_typval(char *str, size_t str_m, const char *fmt, va_list ap_st const char *digstart = p; unsigned uj; - if (get_unsigned_int(digstart, &p, &uj) == FAIL) { - goto error; - } - - if (uj > MAX_ALLOWED_STRING_WIDTH) { - format_overflow_error(digstart); + if (get_unsigned_int(digstart, &p, &uj, tvs != NULL) == FAIL) { goto error; } @@ -1588,12 +1591,7 @@ int vim_vsnprintf_typval(char *str, size_t str_m, const char *fmt, va_list ap_st const char *digstart = p; unsigned uj; - if (get_unsigned_int(digstart, &p, &uj) == FAIL) { - goto error; - } - - if (uj > MAX_ALLOWED_STRING_WIDTH) { - format_overflow_error(digstart); + if (get_unsigned_int(digstart, &p, &uj, tvs != NULL) == FAIL) { goto error; } @@ -1607,7 +1605,7 @@ int vim_vsnprintf_typval(char *str, size_t str_m, const char *fmt, va_list ap_st // positional argument unsigned uj; - if (get_unsigned_int(digstart, &p, &uj) == FAIL) { + if (get_unsigned_int(digstart, &p, &uj, tvs != NULL) == FAIL) { goto error; } @@ -1616,15 +1614,19 @@ int vim_vsnprintf_typval(char *str, size_t str_m, const char *fmt, va_list ap_st p++; } - const int j = (tvs - ? (int)tv_nr(tvs, &arg_idx) - : (skip_to_arg(ap_types, ap_start, &ap, &arg_idx, - &arg_cur, fmt), - va_arg(ap, int))); + int j = (tvs + ? (int)tv_nr(tvs, &arg_idx) + : (skip_to_arg(ap_types, ap_start, &ap, &arg_idx, + &arg_cur, fmt), + va_arg(ap, int))); if (j > MAX_ALLOWED_STRING_WIDTH) { - format_overflow_error(digstart); - goto error; + if (tvs != NULL) { + format_overflow_error(digstart); + goto error; + } else { + j = MAX_ALLOWED_STRING_WIDTH; + } } if (j >= 0) { |