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>
diff --git a/src/vim9instr.c b/src/vim9instr.c
index 4368e3c..b519039 100644
--- a/src/vim9instr.c
+++ b/src/vim9instr.c
@@ -1445,7 +1445,7 @@
}
}
if (ufunc->uf_def_status == UF_NOT_COMPILED || cl != NULL)
- extra->fre_func_name = vim_strsave(ufunc->uf_name);
+ extra->fre_func_name = vim_strnsave(ufunc->uf_name, ufunc->uf_namelen);
if (ufunc->uf_def_status != UF_NOT_COMPILED && cl == NULL)
{
if (isn_idx == NULL && ufunc->uf_def_status == UF_TO_BE_COMPILED)
@@ -1912,7 +1912,7 @@
{
// A user function may be deleted and redefined later, can't use the
// ufunc pointer, need to look it up again at runtime.
- isn->isn_arg.ufunc.cuf_name = vim_strsave(ufunc->uf_name);
+ isn->isn_arg.ufunc.cuf_name = vim_strnsave(ufunc->uf_name, ufunc->uf_namelen);
isn->isn_arg.ufunc.cuf_argcount = argcount;
}