mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 01:34:25 +00:00 
			
		
		
		
	Remove '- 1' for sizes passed to xstrlcpy
xstrlcpy() NUL-terminates the destination string such that reducing the destination string length by 1 to reserve the last byte for NUL is pointless. https://github.com/neovim/neovim/pull/14490#discussion_r635661185
This commit is contained in:
		@@ -1619,7 +1619,7 @@ void list_hashtable_vars(hashtab_T *ht, const char *prefix, int empty,
 | 
			
		||||
      char buf[IOSIZE];
 | 
			
		||||
 | 
			
		||||
      // apply :filter /pat/ to variable name
 | 
			
		||||
      xstrlcpy(buf, prefix, IOSIZE - 1);
 | 
			
		||||
      xstrlcpy(buf, prefix, IOSIZE);
 | 
			
		||||
      xstrlcat(buf, (char *)di->di_key, IOSIZE);
 | 
			
		||||
      if (message_filtered((char_u *)buf)) {
 | 
			
		||||
        continue;
 | 
			
		||||
 
 | 
			
		||||
@@ -1069,7 +1069,7 @@ char_u *get_menu_names(expand_T *xp, int idx)
 | 
			
		||||
#define TBUFFER_LEN 256
 | 
			
		||||
  static char_u tbuffer[TBUFFER_LEN];         /*hack*/
 | 
			
		||||
  char_u              *str;
 | 
			
		||||
  static int should_advance = FALSE;
 | 
			
		||||
  static bool should_advance = false;
 | 
			
		||||
 | 
			
		||||
  if (idx == 0) {           /* first call: start at first item */
 | 
			
		||||
    menu = expand_menu;
 | 
			
		||||
@@ -1089,12 +1089,13 @@ char_u *get_menu_names(expand_T *xp, int idx)
 | 
			
		||||
 | 
			
		||||
  if (menu->modes & expand_modes) {
 | 
			
		||||
    if (menu->children != NULL) {
 | 
			
		||||
      if (should_advance)
 | 
			
		||||
        STRLCPY(tbuffer, menu->en_dname, TBUFFER_LEN - 1);
 | 
			
		||||
      else {
 | 
			
		||||
        STRLCPY(tbuffer, menu->dname,  TBUFFER_LEN - 1);
 | 
			
		||||
        if (menu->en_dname == NULL)
 | 
			
		||||
          should_advance = TRUE;
 | 
			
		||||
      if (should_advance) {
 | 
			
		||||
        STRLCPY(tbuffer, menu->en_dname, TBUFFER_LEN);
 | 
			
		||||
      } else {
 | 
			
		||||
        STRLCPY(tbuffer, menu->dname,  TBUFFER_LEN);
 | 
			
		||||
        if (menu->en_dname == NULL) {
 | 
			
		||||
          should_advance = true;
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      /* hack on menu separators:  use a 'magic' char for the separator
 | 
			
		||||
       * so that '.' in names gets escaped properly */
 | 
			
		||||
@@ -1105,8 +1106,9 @@ char_u *get_menu_names(expand_T *xp, int idx)
 | 
			
		||||
        str = menu->en_dname;
 | 
			
		||||
      else {
 | 
			
		||||
        str = menu->dname;
 | 
			
		||||
        if (menu->en_dname == NULL)
 | 
			
		||||
          should_advance = TRUE;
 | 
			
		||||
        if (menu->en_dname == NULL) {
 | 
			
		||||
          should_advance = true;
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  } else
 | 
			
		||||
 
 | 
			
		||||
@@ -65,7 +65,7 @@ FileComparison path_full_compare(char_u *const s1, char_u *const s2,
 | 
			
		||||
  if (expandenv) {
 | 
			
		||||
      expand_env(s1, exp1, MAXPATHL);
 | 
			
		||||
  } else {
 | 
			
		||||
      xstrlcpy((char *)exp1, (const char *)s1, MAXPATHL - 1);
 | 
			
		||||
      xstrlcpy((char *)exp1, (const char *)s1, MAXPATHL);
 | 
			
		||||
  }
 | 
			
		||||
  bool id_ok_1 = os_fileid((char *)exp1, &file_id_1);
 | 
			
		||||
  bool id_ok_2 = os_fileid((char *)s2, &file_id_2);
 | 
			
		||||
 
 | 
			
		||||
@@ -3919,13 +3919,13 @@ static int qf_buf_add_line(buf_T *buf, linenr_T lnum, const qfline_T *qfp,
 | 
			
		||||
  buf_T *errbuf;
 | 
			
		||||
 | 
			
		||||
  if (qfp->qf_module != NULL) {
 | 
			
		||||
    STRLCPY(IObuff, qfp->qf_module, IOSIZE - 1);
 | 
			
		||||
    STRLCPY(IObuff, qfp->qf_module, IOSIZE);
 | 
			
		||||
    len = (int)STRLEN(IObuff);
 | 
			
		||||
  } else if (qfp->qf_fnum != 0
 | 
			
		||||
             && (errbuf = buflist_findnr(qfp->qf_fnum)) != NULL
 | 
			
		||||
             && errbuf->b_fname != NULL) {
 | 
			
		||||
    if (qfp->qf_type == 1) {  // :helpgrep
 | 
			
		||||
      STRLCPY(IObuff, path_tail(errbuf->b_fname), IOSIZE - 1);
 | 
			
		||||
      STRLCPY(IObuff, path_tail(errbuf->b_fname), IOSIZE);
 | 
			
		||||
    } else {
 | 
			
		||||
      // Shorten the file name if not done already.
 | 
			
		||||
      // For optimization, do this only for the first entry in a
 | 
			
		||||
@@ -3938,7 +3938,7 @@ static int qf_buf_add_line(buf_T *buf, linenr_T lnum, const qfline_T *qfp,
 | 
			
		||||
        }
 | 
			
		||||
        shorten_buf_fname(errbuf, dirname, false);
 | 
			
		||||
      }
 | 
			
		||||
      STRLCPY(IObuff, errbuf->b_fname, IOSIZE - 1);
 | 
			
		||||
      STRLCPY(IObuff, errbuf->b_fname, IOSIZE);
 | 
			
		||||
    }
 | 
			
		||||
    len = (int)STRLEN(IObuff);
 | 
			
		||||
  } else {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user