return name;
}
+/*
+ * Allocate a "ufunc_T" for a function called "name".
+ * Makes sure the size is right.
+ */
+ static ufunc_T *
+alloc_ufunc(char_u *name)
+{
+ // When the name is short we need to make sure we allocate enough bytes for
+ // the whole struct, including any padding.
+ size_t len = offsetof(ufunc_T, uf_name) + STRLEN(name) + 1;
+ return alloc_clear(len < sizeof(ufunc_T) ? sizeof(ufunc_T) : len);
+}
+
#if defined(FEAT_LUA) || defined(PROTO)
/*
* Registers a native C callback which can be called from Vim script.
char_u *name = get_lambda_name();
ufunc_T *fp;
- fp = alloc_clear(offsetof(ufunc_T, uf_name) + STRLEN(name) + 1);
+ fp = alloc_ufunc(name);
if (fp == NULL)
return NULL;
}
name = get_lambda_name();
- ufunc = alloc_clear(offsetof(ufunc_T, uf_name) + STRLEN(name) + 1);
+ ufunc = alloc_ufunc(name);
if (ufunc == NULL)
goto erret;
set_ufunc_name(ufunc, name);
char_u *line_end;
char_u *name = get_lambda_name();
- fp = alloc_clear(offsetof(ufunc_T, uf_name) + STRLEN(name) + 1);
+ fp = alloc_ufunc(name);
if (fp == NULL)
goto errret;
fp->uf_def_status = UF_NOT_COMPILED;
return FAIL;
}
- fp = alloc_clear(offsetof(ufunc_T, uf_name) + STRLEN(global) + 1);
+ fp = alloc_ufunc(global);
if (fp == NULL)
return FAIL;
}
}
- fp = alloc_clear(offsetof(ufunc_T, uf_name) + STRLEN(name) + 1);
+ fp = alloc_ufunc(name);
if (fp == NULL)
goto erret;
fp_allocated = TRUE;
ufunc_T *
copy_function(ufunc_T *fp)
{
- // The struct may have padding, make sure we allocate at least the size of
- // the struct.
- size_t len = offsetof(ufunc_T, uf_name) + STRLEN(fp->uf_name) + 1;
- ufunc_T *ufunc = alloc_clear(len < sizeof(ufunc_T) ? sizeof(ufunc_T) : len);
+ ufunc_T *ufunc = alloc_ufunc(fp->uf_name);
if (ufunc == NULL)
return NULL;