vim-patch:9.1.1467: too many strlen() calls (#34572)

Problem:  too many strlen() calls
Solution: Change expand_env() to return string length
          (John Marriott)

This commit does the following changes:
- In expand_env_esc():
  - return the length of the returned dst string.
  - refactor to remove some calls to STRLEN() and STRCAT()
  - add check for out-of-memory condition.
- Change call sites in various source files to use the return value

closes: vim/vim#17561

fff0132399

Co-authored-by: John Marriott <basilisk@internode.on.net>
This commit is contained in:
zeertzjq
2025-06-19 10:21:33 +08:00
committed by GitHub
parent 8ed6f00ab0
commit fb8dba413f
5 changed files with 45 additions and 31 deletions

View File

@@ -1314,8 +1314,9 @@ static char *shada_filename(const char *file)
// because various expansions must have already be done by the shell.
// If shell is not performing them then they should be done in main.c
// where arguments are parsed, *not here*.
expand_env((char *)file, &(NameBuff[0]), MAXPATHL);
size_t len = expand_env((char *)file, &(NameBuff[0]), MAXPATHL);
file = &(NameBuff[0]);
return xmemdupz(file, len);
}
}
return xstrdup(file);