mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 09:44:31 +00:00 
			
		
		
		
	Merge pull request #29908 from neovim/backport-29907-to-release-0.10
vim-patch:9.1.0638: E1510 may happen when formatting a message for smsg()
This commit is contained in:
		@@ -1002,7 +1002,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)++;
 | 
			
		||||
@@ -1013,8 +1013,12 @@ static int get_unsigned_int(const char *pstart, const char **p, unsigned *uj)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (*uj > MAX_ALLOWED_STRING_WIDTH) {
 | 
			
		||||
    if (overflow_err) {
 | 
			
		||||
      format_overflow_error(pstart);
 | 
			
		||||
      return FAIL;
 | 
			
		||||
    } else {
 | 
			
		||||
      *uj = MAX_ALLOWED_STRING_WIDTH;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return OK;
 | 
			
		||||
@@ -1075,7 +1079,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;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -1118,7 +1122,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;
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
@@ -1144,7 +1148,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;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -1165,7 +1169,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;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
@@ -1192,7 +1196,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;
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
@@ -1488,7 +1492,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;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -1530,7 +1534,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;
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
@@ -1539,15 +1543,19 @@ int vim_vsnprintf_typval(char *str, size_t str_m, const char *fmt, va_list ap_st
 | 
			
		||||
          p++;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        const int j = (tvs
 | 
			
		||||
        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) {
 | 
			
		||||
          if (tvs != NULL) {
 | 
			
		||||
            format_overflow_error(digstart);
 | 
			
		||||
            goto error;
 | 
			
		||||
          } else {
 | 
			
		||||
            j = MAX_ALLOWED_STRING_WIDTH;
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (j >= 0) {
 | 
			
		||||
@@ -1562,12 +1570,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;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -1585,12 +1588,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;
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
@@ -1604,7 +1602,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;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
@@ -1613,15 +1611,19 @@ int vim_vsnprintf_typval(char *str, size_t str_m, const char *fmt, va_list ap_st
 | 
			
		||||
            p++;
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          const int j = (tvs
 | 
			
		||||
          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) {
 | 
			
		||||
            if (tvs != NULL) {
 | 
			
		||||
              format_overflow_error(digstart);
 | 
			
		||||
              goto error;
 | 
			
		||||
            } else {
 | 
			
		||||
              j = MAX_ALLOWED_STRING_WIDTH;
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          if (j >= 0) {
 | 
			
		||||
 
 | 
			
		||||
@@ -757,6 +757,22 @@ func Test_spell_add_word()
 | 
			
		||||
  %bw!
 | 
			
		||||
endfunc
 | 
			
		||||
 | 
			
		||||
func Test_spell_add_long_word()
 | 
			
		||||
  set spell spellfile=./Xspellfile.add spelllang=en
 | 
			
		||||
 | 
			
		||||
  let word = repeat('a', 9000)
 | 
			
		||||
  let v:errmsg = ''
 | 
			
		||||
  " Spell checking doesn't really work for such a long word,
 | 
			
		||||
  " but this should not cause an E1510 error.
 | 
			
		||||
  exe 'spellgood ' .. word
 | 
			
		||||
  call assert_equal('', v:errmsg)
 | 
			
		||||
  call assert_equal([word], readfile('./Xspellfile.add'))
 | 
			
		||||
 | 
			
		||||
  set spell& spellfile= spelllang& encoding=utf-8
 | 
			
		||||
  call delete('./Xspellfile.add')
 | 
			
		||||
  call delete('./Xspellfile.add.spl')
 | 
			
		||||
endfunc
 | 
			
		||||
 | 
			
		||||
func Test_spellfile_verbose()
 | 
			
		||||
  call writefile(['1', 'one'], 'XtestVerbose.dic')
 | 
			
		||||
  call writefile([], 'XtestVerbose.aff')
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user