patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Problem: Alloc() returning "char_u *" causes a lot of type casts.
Solution: Have it return "void *". (Mike Williams) Define ALLOC_ONE() to
check the simple allocations.
diff --git a/src/if_mzsch.c b/src/if_mzsch.c
index f648e74..04a444e 100644
--- a/src/if_mzsch.c
+++ b/src/if_mzsch.c
@@ -2582,7 +2582,7 @@
MZ_GC_VAR_IN_REG(1, rest);
MZ_GC_REG();
- array = (char **)alloc((new_len+1)* sizeof(char *));
+ array = ALLOC_MULT(char *, new_len + 1);
vim_memset(array, 0, (new_len+1) * sizeof(char *));
rest = line_list;
@@ -2766,7 +2766,7 @@
MZ_GC_VAR_IN_REG(1, rest);
MZ_GC_REG();
- array = (char **)alloc((size+1) * sizeof(char *));
+ array = ALLOC_MULT(char *, size + 1);
vim_memset(array, 0, (size+1) * sizeof(char *));
rest = list;
@@ -2886,7 +2886,7 @@
if (memchr(scheme_str, '\n', len))
scheme_signal_error(_("string cannot contain newlines"));
- vim_str = (char *)alloc(len + 1);
+ vim_str = alloc(len + 1);
/* Create a copy of the string, with internal nulls replaced by
* newline characters, as is the vim convention.
@@ -3213,14 +3213,14 @@
tv->vval.v_list = list;
++list->lv_refcount;
- v = (typval_T *)alloc(sizeof(typval_T));
+ v = ALLOC_ONE(typval_T);
if (v == NULL)
status = FAIL;
else
{
/* add the value in advance to allow handling of self-referential
* data structures */
- typval_T *visited_tv = (typval_T *)alloc(sizeof(typval_T));
+ typval_T *visited_tv = ALLOC_ONE(typval_T);
copy_tv(tv, visited_tv);
scheme_hash_set(visited, obj, (Scheme_Object *)visited_tv);
@@ -3288,7 +3288,7 @@
status = FAIL;
else
{
- typval_T *visited_tv = (typval_T *)alloc(sizeof(typval_T));
+ typval_T *visited_tv = ALLOC_ONE(typval_T);
tv->v_type = VAR_DICT;
tv->vval.v_dict = dict;
@@ -3353,7 +3353,7 @@
++list->lv_refcount;
for (i = 0; status == OK && i < argc; ++i)
{
- typval_T *v = (typval_T *)alloc(sizeof(typval_T));
+ typval_T *v = ALLOC_ONE(typval_T);
if (v == NULL)
status = FAIL;
else