mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 01:34:25 +00:00 
			
		
		
		
	option: Do not add unneeded path separator, protect against zero len
This commit is contained in:
		@@ -346,7 +346,7 @@ static inline size_t compute_double_colon_len(const char *const val,
 | 
				
			|||||||
                                              const size_t single_suf_len)
 | 
					                                              const size_t single_suf_len)
 | 
				
			||||||
  FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE
 | 
					  FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  if (val == NULL) {
 | 
					  if (val == NULL && *val) {
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  size_t ret = 0;
 | 
					  size_t ret = 0;
 | 
				
			||||||
@@ -356,7 +356,8 @@ static inline size_t compute_double_colon_len(const char *const val,
 | 
				
			|||||||
    const char *dir;
 | 
					    const char *dir;
 | 
				
			||||||
    iter = vim_colon_env_iter(val, iter, &dir, &dir_len);
 | 
					    iter = vim_colon_env_iter(val, iter, &dir, &dir_len);
 | 
				
			||||||
    if (dir != NULL && dir_len > 0) {
 | 
					    if (dir != NULL && dir_len > 0) {
 | 
				
			||||||
      ret += ((dir_len + count_commas(dir, dir_len) + common_suf_len + 1) * 2
 | 
					      ret += ((dir_len + count_commas(dir, dir_len) + common_suf_len
 | 
				
			||||||
 | 
					               + !after_pathsep(dir, dir + dir_len)) * 2
 | 
				
			||||||
              + single_suf_len);
 | 
					              + single_suf_len);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  } while (iter != NULL);
 | 
					  } while (iter != NULL);
 | 
				
			||||||
@@ -390,7 +391,7 @@ static inline char *add_colon_dirs(char *dest, const char *const val,
 | 
				
			|||||||
                                   const bool forward)
 | 
					                                   const bool forward)
 | 
				
			||||||
  FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_RET FUNC_ATTR_NONNULL_ARG(1)
 | 
					  FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_RET FUNC_ATTR_NONNULL_ARG(1)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  if (val == NULL) {
 | 
					  if (val == NULL && *val) {
 | 
				
			||||||
    return dest;
 | 
					    return dest;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  const void *iter = NULL;
 | 
					  const void *iter = NULL;
 | 
				
			||||||
@@ -401,7 +402,9 @@ static inline char *add_colon_dirs(char *dest, const char *const val,
 | 
				
			|||||||
        val, iter, &dir, &dir_len);
 | 
					        val, iter, &dir, &dir_len);
 | 
				
			||||||
    if (dir != NULL && dir_len > 0) {
 | 
					    if (dir != NULL && dir_len > 0) {
 | 
				
			||||||
      dest = strcpy_comma_escaped(dest, dir, dir_len);
 | 
					      dest = strcpy_comma_escaped(dest, dir, dir_len);
 | 
				
			||||||
 | 
					      if (!after_pathsep(dest - 1, dest)) {
 | 
				
			||||||
        *dest++ = PATHSEP;
 | 
					        *dest++ = PATHSEP;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
      memmove(dest, "nvim", NVIM_SIZE);
 | 
					      memmove(dest, "nvim", NVIM_SIZE);
 | 
				
			||||||
      dest += NVIM_SIZE;
 | 
					      dest += NVIM_SIZE;
 | 
				
			||||||
      if (suf1 != NULL) {
 | 
					      if (suf1 != NULL) {
 | 
				
			||||||
@@ -445,12 +448,14 @@ static inline char *add_dir(char *dest, const char *const dir,
 | 
				
			|||||||
                            const char *const suf2, const size_t len2)
 | 
					                            const char *const suf2, const size_t len2)
 | 
				
			||||||
  FUNC_ATTR_NONNULL_RET FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_WARN_UNUSED_RESULT
 | 
					  FUNC_ATTR_NONNULL_RET FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_WARN_UNUSED_RESULT
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  if (dir == NULL) {
 | 
					  if (dir == NULL && dir_len != 0) {
 | 
				
			||||||
    return dest;
 | 
					    return dest;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  dest = strcpy_comma_escaped(dest, dir, dir_len);
 | 
					  dest = strcpy_comma_escaped(dest, dir, dir_len);
 | 
				
			||||||
  if (append_nvim) {
 | 
					  if (append_nvim) {
 | 
				
			||||||
 | 
					    if (!after_pathsep(dest - 1, dest)) {
 | 
				
			||||||
      *dest++ = PATHSEP;
 | 
					      *dest++ = PATHSEP;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    memmove(dest, "nvim", NVIM_SIZE);
 | 
					    memmove(dest, "nvim", NVIM_SIZE);
 | 
				
			||||||
    dest += NVIM_SIZE;
 | 
					    dest += NVIM_SIZE;
 | 
				
			||||||
    if (suf1 != NULL) {
 | 
					    if (suf1 != NULL) {
 | 
				
			||||||
@@ -484,18 +489,28 @@ static void set_runtimepath_default(void)
 | 
				
			|||||||
  size_t vimruntime_len;
 | 
					  size_t vimruntime_len;
 | 
				
			||||||
  if (data_home != NULL) {
 | 
					  if (data_home != NULL) {
 | 
				
			||||||
    data_len = strlen(data_home);
 | 
					    data_len = strlen(data_home);
 | 
				
			||||||
 | 
					    if (data_len != 0) {
 | 
				
			||||||
      rtp_size += ((data_len + count_commas(data_home, data_len)
 | 
					      rtp_size += ((data_len + count_commas(data_home, data_len)
 | 
				
			||||||
                  + NVIM_SIZE + 1 + SITE_SIZE + 1 + 1) * 2 + AFTER_SIZE + 1);
 | 
					                    + NVIM_SIZE + 1 + SITE_SIZE + 1
 | 
				
			||||||
 | 
					                    + !after_pathsep(data_home, data_home + data_len)) * 2
 | 
				
			||||||
 | 
					                   + AFTER_SIZE + 1);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if (config_home != NULL) {
 | 
					  if (config_home != NULL) {
 | 
				
			||||||
    config_len = strlen(config_home);
 | 
					    config_len = strlen(config_home);
 | 
				
			||||||
 | 
					    if (config_len != 0) {
 | 
				
			||||||
      rtp_size += ((config_len + count_commas(config_home, config_len)
 | 
					      rtp_size += ((config_len + count_commas(config_home, config_len)
 | 
				
			||||||
                  + NVIM_SIZE + 1 + 1) * 2 + AFTER_SIZE + 1);
 | 
					                    + NVIM_SIZE + 1
 | 
				
			||||||
 | 
					                    + !after_pathsep(config_home, config_home + config_len)) * 2
 | 
				
			||||||
 | 
					                   + AFTER_SIZE + 1);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if (vimruntime != NULL) {
 | 
					  if (vimruntime != NULL) {
 | 
				
			||||||
    vimruntime_len = strlen(vimruntime);
 | 
					    vimruntime_len = strlen(vimruntime);
 | 
				
			||||||
 | 
					    if (vimruntime_len != 0) {
 | 
				
			||||||
      rtp_size += vimruntime_len + count_commas(vimruntime, vimruntime_len) + 1;
 | 
					      rtp_size += vimruntime_len + count_commas(vimruntime, vimruntime_len) + 1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  rtp_size += compute_double_colon_len(data_dirs, NVIM_SIZE + 1 + SITE_SIZE + 1,
 | 
					  rtp_size += compute_double_colon_len(data_dirs, NVIM_SIZE + 1 + SITE_SIZE + 1,
 | 
				
			||||||
                                       AFTER_SIZE + 1);
 | 
					                                       AFTER_SIZE + 1);
 | 
				
			||||||
  rtp_size += compute_double_colon_len(config_dirs, NVIM_SIZE + 1,
 | 
					  rtp_size += compute_double_colon_len(config_dirs, NVIM_SIZE + 1,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user