patch 9.1.1063: too many strlen() calls in userfunc.c

Problem:  too many strlen() calls in userfunc.c
Solution: refactor userfunc.c and remove calls to strlen(),
          drop set_ufunc_name() and roll it into alloc_ufunc(),
          check for out-of-memory condition in trans_function_name_ext()
          (John Marriott)

closes: #16537

Signed-off-by: John Marriott <basilisk@internode.on.net>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
John Marriott
2025-02-01 15:25:34 +01:00
committed by Christian Brabandt
parent 3219da514c
commit b32800f7c5
9 changed files with 192 additions and 114 deletions

View File

@ -544,7 +544,7 @@ dict_add_func(dict_T *d, char *key, ufunc_T *fp)
if (item == NULL)
return FAIL;
item->di_tv.v_type = VAR_FUNC;
item->di_tv.vval.v_string = vim_strsave(fp->uf_name);
item->di_tv.vval.v_string = vim_strnsave(fp->uf_name, fp->uf_namelen);
if (dict_add(d, item) == FAIL)
{
dictitem_free(item);