changeset 16825:ce04ebdf26b8 v8.1.1414

patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts commit https://github.com/vim/vim/commit/c799fe206e61f2e2c1231bc46cbe4bb354f3da69 Author: Bram Moolenaar <Bram@vim.org> Date: Tue May 28 23:08:19 2019 +0200 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.
author Bram Moolenaar <Bram@vim.org>
date Tue, 28 May 2019 23:15:10 +0200
parents 1f6bb29738d2
children aff339110438
files src/autocmd.c src/blob.c src/blowfish.c src/buffer.c src/change.c src/channel.c src/crypt.c src/crypt_zip.c src/dict.c src/diff.c src/eval.c src/evalfunc.c src/ex_cmds.c src/ex_cmds2.c src/ex_docmd.c src/ex_eval.c src/ex_getln.c src/fileio.c src/findfile.c src/getchar.c src/gui_gtk.c src/gui_gtk_x11.c src/gui_mac.c src/gui_motif.c src/gui_photon.c src/gui_w32.c src/gui_x11.c src/hardcopy.c src/hashtab.c src/if_cscope.c src/if_mzsch.c src/if_perlsfio.c src/if_py_both.h src/if_python3.c src/if_xcmdsrv.c src/insexpand.c src/list.c src/mark.c src/mbyte.c src/memfile.c src/memfile_test.c src/memline.c src/message.c src/misc2.c src/netbeans.c src/normal.c src/ops.c src/option.c src/os_amiga.c src/os_mac_conv.c src/os_mswin.c src/os_unix.c src/os_vms.c src/os_win32.c src/popupmnu.c src/proto/misc2.pro src/quickfix.c src/regexp.c src/regexp_nfa.c src/screen.c src/search.c src/sign.c src/spell.c src/spellfile.c src/syntax.c src/tag.c src/term.c src/terminal.c src/testdir/test_cscope.vim src/textprop.c src/ui.c src/undo.c src/userfunc.c src/version.c src/vim.h src/winclip.c src/window.c
diffstat 77 files changed, 382 insertions(+), 419 deletions(-) [+]
line wrap: on
line diff
--- a/src/autocmd.c
+++ b/src/autocmd.c
@@ -1193,7 +1193,7 @@ do_autocmd_event(
 		    return FAIL;
 		}
 
-		ap = (AutoPat *)alloc(sizeof(AutoPat));
+		ap = ALLOC_ONE(AutoPat);
 		if (ap == NULL)
 		    return FAIL;
 		ap->pat = vim_strnsave(pat, patlen);
@@ -1242,7 +1242,7 @@ do_autocmd_event(
 	    prev_ac = &(ap->cmds);
 	    while ((ac = *prev_ac) != NULL)
 		prev_ac = &ac->next;
-	    ac = (AutoCmd *)alloc(sizeof(AutoCmd));
+	    ac = ALLOC_ONE(AutoCmd);
 	    if (ac == NULL)
 		return FAIL;
 	    ac->cmd = vim_strsave(cmd);
--- a/src/blob.c
+++ b/src/blob.c
@@ -22,7 +22,7 @@
     blob_T *
 blob_alloc(void)
 {
-    blob_T *blob = (blob_T *)alloc_clear(sizeof(blob_T));
+    blob_T *blob = ALLOC_CLEAR_ONE(blob_T);
 
     if (blob != NULL)
 	ga_init2(&blob->bv_ga, 1, 100);
--- a/src/blowfish.c
+++ b/src/blowfish.c
@@ -645,7 +645,7 @@ crypt_blowfish_init(
     char_u*		seed,
     int			seed_len)
 {
-    bf_state_T	*bfs = (bf_state_T *)alloc_clear(sizeof(bf_state_T));
+    bf_state_T	*bfs = ALLOC_CLEAR_ONE(bf_state_T);
 
     if (bfs == NULL)
 	return FAIL;
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1958,7 +1958,7 @@ buflist_new(
     }
     if (buf != curbuf || curbuf == NULL)
     {
-	buf = (buf_T *)alloc_clear(sizeof(buf_T));
+	buf = ALLOC_CLEAR_ONE(buf_T);
 	if (buf == NULL)
 	{
 	    vim_free(ffname);
@@ -1985,7 +1985,7 @@ buflist_new(
     }
 
     clear_wininfo(buf);
-    buf->b_wininfo = (wininfo_T *)alloc_clear(sizeof(wininfo_T));
+    buf->b_wininfo = ALLOC_CLEAR_ONE(wininfo_T);
 
     if ((ffname != NULL && (buf->b_ffname == NULL || buf->b_sfname == NULL))
 	    || buf->b_wininfo == NULL)
@@ -2634,7 +2634,7 @@ ExpandBufnames(
 		break;
 	    if (round == 1)
 	    {
-		*file = (char_u **)alloc(count * sizeof(char_u *));
+		*file = ALLOC_MULT(char_u *, count);
 		if (*file == NULL)
 		{
 		    vim_regfree(regmatch.regprog);
@@ -2771,7 +2771,7 @@ buflist_setfpos(
     if (wip == NULL)
     {
 	/* allocate a new entry */
-	wip = (wininfo_T *)alloc_clear(sizeof(wininfo_T));
+	wip = ALLOC_CLEAR_ONE(wininfo_T);
 	if (wip == NULL)
 	    return;
 	wip->wi_win = win;
@@ -3430,7 +3430,7 @@ fileinfo(
     char	*buffer;
     size_t	len;
 
-    buffer = (char *)alloc(IOSIZE);
+    buffer = alloc(IOSIZE);
     if (buffer == NULL)
 	return;
 
--- a/src/change.c
+++ b/src/change.c
@@ -286,7 +286,7 @@ f_listener_add(typval_T *argvars, typval
 	    return;
     }
 
-    lnr = (listener_T *)alloc_clear(sizeof(listener_T));
+    lnr = ALLOC_CLEAR_ONE(listener_T);
     if (lnr == NULL)
     {
 	free_callback(callback, partial);
--- a/src/channel.c
+++ b/src/channel.c
@@ -294,7 +294,7 @@ static int next_ch_id = 0;
 add_channel(void)
 {
     ch_part_T	part;
-    channel_T	*channel = (channel_T *)alloc_clear(sizeof(channel_T));
+    channel_T	*channel = ALLOC_CLEAR_ONE(channel_T);
 
     if (channel == NULL)
 	return NULL;
@@ -1354,7 +1354,7 @@ channel_set_req_callback(
 	int	    id)
 {
     cbq_T *head = &channel->ch_part[part].ch_cb_head;
-    cbq_T *item = (cbq_T *)alloc(sizeof(cbq_T));
+    cbq_T *item = ALLOC_ONE(cbq_T);
 
     if (item != NULL)
     {
@@ -1875,7 +1875,7 @@ channel_save(channel_T *channel, ch_part
     char_u  *p;
     int	    i;
 
-    node = (readq_T *)alloc(sizeof(readq_T));
+    node = ALLOC_ONE(readq_T);
     if (node == NULL)
 	return FAIL;	    /* out of memory */
     /* A NUL is added at the end, because netbeans code expects that.
@@ -2024,7 +2024,7 @@ channel_parse_json(channel_T *channel, c
 	}
 	else
 	{
-	    item = (jsonq_T *)alloc(sizeof(jsonq_T));
+	    item = ALLOC_ONE(jsonq_T);
 	    if (item == NULL)
 		clear_tv(&listtv);
 	    else
@@ -2223,7 +2223,7 @@ channel_push_json(channel_T *channel, ch
 	/* append after the last item that was pushed back */
 	item = item->jq_next;
 
-    newitem = (jsonq_T *)alloc(sizeof(jsonq_T));
+    newitem = ALLOC_ONE(jsonq_T);
     if (newitem == NULL)
 	clear_tv(rettv);
     else
@@ -3921,7 +3921,7 @@ channel_send(
 		}
 		else
 		{
-		    writeq_T *last = (writeq_T *)alloc(sizeof(writeq_T));
+		    writeq_T *last = ALLOC_ONE(writeq_T);
 
 		    if (last != NULL)
 		    {
@@ -5593,7 +5593,7 @@ job_alloc(void)
 {
     job_T *job;
 
-    job = (job_T *)alloc_clear(sizeof(job_T));
+    job = ALLOC_CLEAR_ONE(job_T);
     if (job != NULL)
     {
 	job->jv_refcount = 1;
@@ -5822,7 +5822,7 @@ job_start(
 	/* Make a copy of argv_arg for job->jv_argv. */
 	for (i = 0; argv_arg[i] != NULL; i++)
 	    argc++;
-	argv = (char **)alloc(sizeof(char *) * (argc + 1));
+	argv = ALLOC_MULT(char *, argc + 1);
 	if (argv == NULL)
 	    goto theend;
 	for (i = 0; i < argc; i++)
--- a/src/crypt.c
+++ b/src/crypt.c
@@ -254,7 +254,7 @@ crypt_create(
     char_u	*seed,
     int		seed_len)
 {
-    cryptstate_T *state = (cryptstate_T *)alloc(sizeof(cryptstate_T));
+    cryptstate_T *state = ALLOC_ONE(cryptstate_T);
 
     if (state == NULL)
 	return state;
--- a/src/crypt_zip.c
+++ b/src/crypt_zip.c
@@ -90,7 +90,7 @@ crypt_zip_init(
     char_u	*p;
     zip_state_T	*zs;
 
-    zs = (zip_state_T *)alloc(sizeof(zip_state_T));
+    zs = ALLOC_ONE(zip_state_T);
     if (zs == NULL)
 	return FAIL;
     state->method_state = zs;
--- a/src/dict.c
+++ b/src/dict.c
@@ -28,7 +28,7 @@ dict_alloc(void)
 {
     dict_T *d;
 
-    d = (dict_T *)alloc(sizeof(dict_T));
+    d = ALLOC_ONE(dict_T);
     if (d != NULL)
     {
 	/* Add the dict to the list of dicts for garbage collection. */
@@ -210,7 +210,7 @@ dictitem_alloc(char_u *key)
 {
     dictitem_T *di;
 
-    di = (dictitem_T *)alloc(sizeof(dictitem_T) + STRLEN(key));
+    di = alloc(sizeof(dictitem_T) + STRLEN(key));
     if (di != NULL)
     {
 	STRCPY(di->di_key, key);
@@ -228,7 +228,7 @@ dictitem_copy(dictitem_T *org)
 {
     dictitem_T *di;
 
-    di = (dictitem_T *)alloc(sizeof(dictitem_T) + STRLEN(org->di_key));
+    di = alloc(sizeof(dictitem_T) + STRLEN(org->di_key));
     if (di != NULL)
     {
 	STRCPY(di->di_key, org->di_key);
--- a/src/diff.c
+++ b/src/diff.c
@@ -537,7 +537,7 @@ diff_alloc_new(tabpage_T *tp, diff_T *dp
 {
     diff_T	*dnew;
 
-    dnew = (diff_T *)alloc(sizeof(diff_T));
+    dnew = ALLOC_ONE(diff_T);
     if (dnew != NULL)
     {
 	dnew->df_next = dp;
--- a/src/eval.c
+++ b/src/eval.c
@@ -491,7 +491,7 @@ var_redir_start(char_u *name, int append
     if (redir_varname == NULL)
 	return FAIL;
 
-    redir_lval = (lval_T *)alloc_clear(sizeof(lval_T));
+    redir_lval = ALLOC_CLEAR_ONE(lval_T);
     if (redir_lval == NULL)
     {
 	var_redir_stop();
@@ -1063,7 +1063,7 @@ eval_expr(char_u *arg, char_u **nextcmd)
 {
     typval_T	*tv;
 
-    tv = (typval_T *)alloc(sizeof(typval_T));
+    tv = ALLOC_ONE(typval_T);
     if (tv != NULL && eval0(arg, tv, nextcmd, TRUE) == FAIL)
 	VIM_CLEAR(tv);
 
@@ -2769,7 +2769,7 @@ eval_for_line(
 
     *errp = TRUE;	/* default: there is an error */
 
-    fi = (forinfo_T *)alloc_clear(sizeof(forinfo_T));
+    fi = ALLOC_CLEAR_ONE(forinfo_T);
     if (fi == NULL)
 	return NULL;
 
@@ -7297,7 +7297,7 @@ handle_subscript(
     typval_T *
 alloc_tv(void)
 {
-    return (typval_T *)alloc_clear(sizeof(typval_T));
+    return ALLOC_CLEAR_ONE(typval_T);
 }
 
 /*
@@ -7883,7 +7883,7 @@ new_script_vars(scid_T id)
 	while (ga_scripts.ga_len < id)
 	{
 	    sv = SCRIPT_SV(ga_scripts.ga_len + 1) =
-		(scriptvar_T *)alloc_clear(sizeof(scriptvar_T));
+		ALLOC_CLEAR_ONE(scriptvar_T);
 	    init_var_dict(&sv->sv_dict, &sv->sv_var, VAR_SCOPE);
 	    ++ga_scripts.ga_len;
 	}
@@ -8139,7 +8139,7 @@ set_var(
 	if (!valid_varname(varname))
 	    return;
 
-	v = (dictitem_T *)alloc(sizeof(dictitem_T) + STRLEN(varname));
+	v = alloc(sizeof(dictitem_T) + STRLEN(varname));
 	if (v == NULL)
 	    return;
 	STRCPY(v->di_key, varname);
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -4465,7 +4465,7 @@ common_function(typval_T *argvars, typva
 	}
 	if (dict_idx > 0 || arg_idx > 0 || arg_pt != NULL || is_funcref)
 	{
-	    partial_T	*pt = (partial_T *)alloc_clear(sizeof(partial_T));
+	    partial_T	*pt = ALLOC_CLEAR_ONE(partial_T);
 
 	    /* result is a VAR_PARTIAL */
 	    if (pt == NULL)
@@ -4484,8 +4484,7 @@ common_function(typval_T *argvars, typva
 		    if (list != NULL)
 			lv_len = list->lv_len;
 		    pt->pt_argc = arg_len + lv_len;
-		    pt->pt_argv = (typval_T *)alloc(
-					      sizeof(typval_T) * pt->pt_argc);
+		    pt->pt_argv = ALLOC_MULT(typval_T, pt->pt_argc);
 		    if (pt->pt_argv == NULL)
 		    {
 			vim_free(pt);
@@ -9615,8 +9614,7 @@ f_readfile(typval_T *argvars, typval_T *
 		    long growmin  = (long)((p - start) * 2 + prevlen);
 		    prevsize = grow50pc > growmin ? grow50pc : growmin;
 		}
-		newprev = prev == NULL ? alloc(prevsize)
-						: vim_realloc(prev, prevsize);
+		newprev = vim_realloc(prev, prevsize);
 		if (newprev == NULL)
 		{
 		    do_outofmem_msg((long_u)prevsize);
@@ -11788,7 +11786,7 @@ f_setreg(typval_T *argvars, typval_T *re
 
 	/* First half: use for pointers to result lines; second half: use for
 	 * pointers to allocated copies. */
-	lstval = (char_u **)alloc(sizeof(char_u *) * ((len + 1) * 2));
+	lstval = ALLOC_MULT(char_u *, (len + 1) * 2);
 	if (lstval == NULL)
 	    return;
 	curval = lstval;
@@ -12674,7 +12672,7 @@ do_sort_uniq(typval_T *argvars, typval_T
 	}
 
 	/* Make an array with each entry pointing to an item in the List. */
-	ptrs = (sortItem_T *)alloc(len * sizeof(sortItem_T));
+	ptrs = ALLOC_MULT(sortItem_T, len);
 	if (ptrs == NULL)
 	    goto theend;
 
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -397,7 +397,7 @@ ex_sort(exarg_T *eap)
     sortbuf1 = NULL;
     sortbuf2 = NULL;
     regmatch.regprog = NULL;
-    nrs = (sorti_T *)alloc(count * sizeof(sorti_T));
+    nrs = ALLOC_MULT(sorti_T, count);
     if (nrs == NULL)
 	goto sortend;
 
--- a/src/ex_cmds2.c
+++ b/src/ex_cmds2.c
@@ -293,7 +293,7 @@ free_timer(timer_T *timer)
     timer_T *
 create_timer(long msec, int repeat)
 {
-    timer_T	*timer = (timer_T *)alloc_clear(sizeof(timer_T));
+    timer_T	*timer = ALLOC_CLEAR_ONE(timer_T);
     long	prev_id = last_timer_id;
 
     if (timer == NULL)
@@ -444,7 +444,7 @@ check_due_timer(void)
 	    bevalexpr_due_set = FALSE;
 	    if (balloonEval == NULL)
 	    {
-		balloonEval = (BalloonEval *)alloc_clear(sizeof(BalloonEval));
+		balloonEval = ALLOC_CLEAR_ONE(BalloonEval);
 		balloonEvalForTerm = TRUE;
 	    }
 	    if (balloonEval != NULL)
@@ -1312,7 +1312,7 @@ check_changed_any(
     if (bufcount == 0)
 	return FALSE;
 
-    bufnrs = (int *)alloc(sizeof(int) * bufcount);
+    bufnrs = ALLOC_MULT(int, bufcount);
     if (bufnrs == NULL)
 	return FALSE;
 
@@ -1783,7 +1783,7 @@ ex_args(exarg_T *eap)
 	 */
 	if (ARGCOUNT > 0)
 	{
-	    char_u **items = (char_u **)alloc(sizeof(char_u *) * ARGCOUNT);
+	    char_u **items = ALLOC_MULT(char_u *, ARGCOUNT);
 
 	    if (items != NULL)
 	    {
@@ -2994,7 +2994,7 @@ ex_packadd(exarg_T *eap)
 	    continue;
 
 	len = (int)STRLEN(plugpat) + (int)STRLEN(eap->arg) + 5;
-	pat = (char *)alloc(len);
+	pat = alloc(len);
 	if (pat == NULL)
 	    return;
 	vim_snprintf(pat, len, plugpat, round == 1 ? "start" : "opt", eap->arg);
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -6550,7 +6550,7 @@ alist_unlink(alist_T *al)
     void
 alist_new(void)
 {
-    curwin->w_alist = (alist_T *)alloc(sizeof(alist_T));
+    curwin->w_alist = ALLOC_ONE(alist_T);
     if (curwin->w_alist == NULL)
     {
 	curwin->w_alist = &global_alist;
@@ -6584,7 +6584,7 @@ alist_expand(int *fnum_list, int fnum_le
      * expansion.  Also, the vimrc file isn't read yet, thus the user
      * can't set the options. */
     p_su = empty_option;
-    old_arg_files = (char_u **)alloc(sizeof(char_u *) * GARGCOUNT);
+    old_arg_files = ALLOC_MULT(char_u *, GARGCOUNT);
     if (old_arg_files != NULL)
     {
 	for (i = 0; i < GARGCOUNT; ++i)
--- a/src/ex_eval.c
+++ b/src/ex_eval.c
@@ -251,7 +251,7 @@ cause_errthrow(
 	    while (*plist != NULL)
 		plist = &(*plist)->next;
 
-	    elem = (struct msglist *)alloc(sizeof(struct msglist));
+	    elem = ALLOC_ONE(struct msglist);
 	    if (elem == NULL)
 	    {
 		suppress_errthrow = TRUE;
@@ -519,7 +519,7 @@ throw_exception(void *value, except_type
 	}
     }
 
-    excp = (except_T *)alloc(sizeof(except_T));
+    excp = ALLOC_ONE(except_T);
     if (excp == NULL)
 	goto nomem;
 
@@ -1441,7 +1441,7 @@ ex_try(exarg_T *eap)
 	    {
 		eslist_T	*elem;
 
-		elem = (eslist_T *)alloc(sizeof(struct eslist_elem));
+		elem = ALLOC_ONE(struct eslist_elem);
 		if (elem == NULL)
 		    emsg(_(e_outofmem));
 		else
--- a/src/ex_getln.c
+++ b/src/ex_getln.c
@@ -5294,7 +5294,7 @@ ExpandGeneric(
 	    if (count == 0)
 		return OK;
 	    *num_file = count;
-	    *file = (char_u **)alloc(count * sizeof(char_u *));
+	    *file = ALLOC_MULT(char_u *, count);
 	    if (*file == NULL)
 	    {
 		*file = (char_u **)"";
@@ -5914,7 +5914,7 @@ init_history(void)
 	{
 	    if (newlen)
 	    {
-		temp = (histentry_T *)alloc(newlen * sizeof(histentry_T));
+		temp = ALLOC_MULT(histentry_T, newlen);
 		if (temp == NULL)   /* out of memory! */
 		{
 		    if (type == 0)  /* first one: just keep the old length */
@@ -6653,8 +6653,7 @@ prepare_viminfo_history(int asklen, int 
 	if (len <= 0)
 	    viminfo_history[type] = NULL;
 	else
-	    viminfo_history[type] = (histentry_T *)lalloc(
-					    len * sizeof(histentry_T), FALSE);
+	    viminfo_history[type] = LALLOC_MULT(histentry_T, len);
 	if (viminfo_history[type] == NULL)
 	    len = 0;
 	viminfo_hislen[type] = len;
@@ -6873,8 +6872,8 @@ merge_history(int type)
 
     /* Make one long list with all entries. */
     max_len = hislen + viminfo_hisidx[type];
-    tot_hist = (histentry_T **)alloc(max_len * (int)sizeof(histentry_T *));
-    new_hist = (histentry_T *)alloc(hislen * (int)sizeof(histentry_T));
+    tot_hist = ALLOC_MULT(histentry_T *, max_len);
+    new_hist = ALLOC_MULT(histentry_T, hislen );
     if (tot_hist == NULL || new_hist == NULL)
     {
 	vim_free(tot_hist);
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -6533,7 +6533,7 @@ vim_rename(char_u *from, char_u *to)
 	return -1;
     }
 
-    buffer = (char *)alloc(BUFSIZE);
+    buffer = alloc(BUFSIZE);
     if (buffer == NULL)
     {
 	close(fd_out);
@@ -6890,8 +6890,7 @@ buf_check_timestamp(
 	{
 	    if (!helpmesg)
 		mesg2 = "";
-	    tbuf = (char *)alloc(STRLEN(path) + STRLEN(mesg)
-							  + STRLEN(mesg2) + 2);
+	    tbuf = alloc(STRLEN(path) + STRLEN(mesg) + STRLEN(mesg2) + 2);
 	    sprintf(tbuf, mesg, path);
 #ifdef FEAT_EVAL
 	    /* Set warningmsg here, before the unimportant and output-specific
--- a/src/findfile.c
+++ b/src/findfile.c
@@ -319,7 +319,7 @@ vim_findfile_init(
 	search_ctx = search_ctx_arg;
     else
     {
-	search_ctx = (ff_search_ctx_T*)alloc(sizeof(ff_search_ctx_T));
+	search_ctx = ALLOC_ONE(ff_search_ctx_T);
 	if (search_ctx == NULL)
 	    goto error_return;
 	vim_memset(search_ctx, 0, sizeof(ff_search_ctx_T));
@@ -350,7 +350,7 @@ vim_findfile_init(
 
     if (ff_expand_buffer == NULL)
     {
-	ff_expand_buffer = (char_u*)alloc(MAXPATHL);
+	ff_expand_buffer = alloc(MAXPATHL);
 	if (ff_expand_buffer == NULL)
 	    goto error_return;
     }
@@ -430,7 +430,7 @@ vim_findfile_init(
 	    walker++;
 
 	dircount = 1;
-	search_ctx->ffsc_stopdirs_v = (char_u **)alloc(sizeof(char_u *));
+	search_ctx->ffsc_stopdirs_v = ALLOC_ONE(char_u *);
 
 	if (search_ctx->ffsc_stopdirs_v != NULL)
 	{
@@ -925,7 +925,7 @@ vim_findfile(void *search_ctx_arg)
 		 */
 		if (path_with_url(dirptrs[0]))
 		{
-		    stackp->ffs_filearray = (char_u **)alloc(sizeof(char *));
+		    stackp->ffs_filearray = ALLOC_ONE(char_u *);
 		    if (stackp->ffs_filearray != NULL
 			    && (stackp->ffs_filearray[0]
 				= vim_strsave(dirptrs[0])) != NULL)
@@ -1283,7 +1283,7 @@ ff_get_visited_list(
     /*
      * if we reach this we didn't find a list and we have to allocate new list
      */
-    retptr = (ff_visited_list_hdr_T*)alloc(sizeof(*retptr));
+    retptr = ALLOC_ONE(ff_visited_list_hdr_T);
     if (retptr == NULL)
 	return NULL;
 
@@ -1411,7 +1411,7 @@ ff_check_visited(
     /*
      * New file/dir.  Add it to the list of visited files/dirs.
      */
-    vp = (ff_visited_T *)alloc(sizeof(ff_visited_T) + STRLEN(ff_expand_buffer));
+    vp = alloc(sizeof(ff_visited_T) + STRLEN(ff_expand_buffer));
 
     if (vp != NULL)
     {
@@ -1459,7 +1459,7 @@ ff_create_stack_element(
 {
     ff_stack_T	*new;
 
-    new = (ff_stack_T *)alloc(sizeof(ff_stack_T));
+    new = ALLOC_ONE(ff_stack_T);
     if (new == NULL)
 	return NULL;
 
@@ -2429,7 +2429,7 @@ uniquefy_paths(garray_T *gap, char_u *pa
     mch_dirname(curdir, MAXPATHL);
     expand_path_option(curdir, &path_ga);
 
-    in_curdir = (char_u **)alloc_clear(gap->ga_len * sizeof(char_u *));
+    in_curdir = ALLOC_CLEAR_MULT(char_u *, gap->ga_len);
     if (in_curdir == NULL)
 	goto theend;
 
--- a/src/getchar.c
+++ b/src/getchar.c
@@ -258,7 +258,7 @@ add_buff(
 	    len = MINIMAL_SIZE;
 	else
 	    len = slen;
-	p = (buffblock_T *)alloc(sizeof(buffblock_T) + len);
+	p = alloc(sizeof(buffblock_T) + len);
 	if (p == NULL)
 	    return; /* no space, just forget it */
 	buf->bh_space = (int)(len - slen);
@@ -3730,7 +3730,7 @@ do_map(
     /*
      * Get here when adding a new entry to the maphash[] list or abbrlist.
      */
-    mp = (mapblock_T *)alloc(sizeof(mapblock_T));
+    mp = ALLOC_ONE(mapblock_T);
     if (mp == NULL)
     {
 	retval = 4;	    /* no mem */
@@ -4374,7 +4374,7 @@ ExpandMappings(
 
 	if (round == 1)
 	{
-	    *file = (char_u **)alloc(count * sizeof(char_u *));
+	    *file = ALLOC_MULT(char_u *, count);
 	    if (*file == NULL)
 		return FAIL;
 	}
--- a/src/gui_gtk.c
+++ b/src/gui_gtk.c
@@ -1452,7 +1452,7 @@ split_button_string(char_u *button_strin
 	if (*p == DLG_BUTTON_SEP)
 	    ++count;
 
-    array = (char **)alloc((count + 1) * sizeof(char *));
+    array = ALLOC_MULT(char *, count + 1);
     count = 0;
 
     if (array != NULL)
--- a/src/gui_gtk_x11.c
+++ b/src/gui_gtk_x11.c
@@ -429,7 +429,7 @@ gui_mch_prepare(int *argc, char **argv)
      * into gui_argv.  Freed later in gui_mch_init().
      */
     gui_argc = 0;
-    gui_argv = (char **)alloc((*argc + 1) * sizeof(char *));
+    gui_argv = ALLOC_MULT(char *, *argc + 1);
 
     g_return_if_fail(gui_argv != NULL);
 
@@ -2157,10 +2157,10 @@ parse_uri_list(int *count, char_u *data,
     char_u  *tmp    = NULL;
     char_u  **array = NULL;
 
-    if (data != NULL && len > 0 && (tmp = (char_u *)alloc(len + 1)) != NULL)
+    if (data != NULL && len > 0 && (tmp = alloc(len + 1)) != NULL)
     {
 	n = count_and_decode_uri_list(tmp, data, len);
-	if (n > 0 && (array = (char_u **)alloc(n * sizeof(char_u *))) != NULL)
+	if (n > 0 && (array = ALLOC_MULT(char_u *, n)) != NULL)
 	    n = filter_uri_list(array, n, tmp);
     }
     vim_free(tmp);
@@ -2512,7 +2512,7 @@ setup_save_yourself(void)
 	    if (i == count)
 	    {
 		/* allocate an Atoms array which is one item longer */
-		new_atoms = (Atom *)alloc((count + 1) * sizeof(Atom));
+		new_atoms = ALLOC_MULT(Atom, count + 1);
 		if (new_atoms != NULL)
 		{
 		    memcpy(new_atoms, existing_atoms, count * sizeof(Atom));
--- a/src/gui_mac.c
+++ b/src/gui_mac.c
@@ -536,7 +536,7 @@ new_fnames_from_AEDesc(AEDesc *theList, 
 	return fnames;
 
     /* Allocate the pointer list */
-    fnames = (char_u **) alloc(*numFiles * sizeof(char_u *));
+    fnames = ALLOC_MULT(char_u *, *numFiles);
 
     /* Empty out the list */
     for (fileCount = 0; fileCount < *numFiles; fileCount++)
@@ -2105,7 +2105,7 @@ gui_mac_unicode_key_event(
 		typeUnicodeText, NULL, 0, &actualSize, NULL))
 	return eventNotHandledErr;
 
-    text = (UniChar *)alloc(actualSize);
+    text = alloc(actualSize);
     if (!text)
 	return eventNotHandledErr;
 
@@ -2975,7 +2975,7 @@ receiveHandler(WindowRef theWindow, void
 	count = countItem;
     }
 
-    fnames = (char_u **)alloc(count * sizeof(char_u *));
+    fnames = ALLOC_MULT(char_u *, count);
     if (fnames == NULL)
 	return dragNotAcceptedErr;
 
--- a/src/gui_motif.c
+++ b/src/gui_motif.c
@@ -2538,7 +2538,7 @@ gui_mch_dialog(
     for (p = buts; *p; ++p)
 	if (*p == DLG_BUTTON_SEP)
 	    ++butcount;
-    buttons = (Widget *)alloc(butcount * sizeof(Widget));
+    buttons = ALLOC_MULT(Widget, butcount);
     if (buttons == NULL)
     {
 	vim_free(buts);
--- a/src/gui_photon.c
+++ b/src/gui_photon.c
@@ -976,7 +976,7 @@ gui_ph_pg_add_buffer(char *name)
 {
     char **new_titles = NULL;
 
-    new_titles = (char **) alloc((num_panels + 1) * sizeof(char **));
+    new_titles = ALLOC_MULT(char *, (num_panels + 1));
     if (new_titles != NULL)
     {
 	if (num_panels > 0)
@@ -1001,7 +1001,7 @@ gui_ph_pg_remove_buffer(char *name)
     /* If there is only 1 panel, we just use the temporary place holder */
     if (num_panels > 1)
     {
-	new_titles = (char **) alloc((num_panels - 1) * sizeof(char **));
+	new_titles = ALLOC_MULT(char *, num_panels - 1);
 	if (new_titles != NULL)
 	{
 	    char **s = new_titles;
@@ -1108,7 +1108,7 @@ gui_mch_init(void)
     PhDim_t	window_size = {100, 100}; /* Arbitrary values */
     PhPoint_t	pos = {0, 0};
 
-    gui.event_buffer = (PhEvent_t *) alloc(EVENT_BUFFER_SIZE);
+    gui.event_buffer = alloc(EVENT_BUFFER_SIZE);
     if (gui.event_buffer == NULL)
 	return FAIL;
 
@@ -1519,7 +1519,7 @@ gui_mch_dialog(
 	title = "Vim";
 
     buttons_copy = alloc(len + 1);
-    button_array = (char_u **) alloc(button_count * sizeof(char_u *));
+    button_array = ALLOC_MULT(char_u *, button_count);
     if (buttons_copy != NULL && button_array != NULL)
     {
 	STRCPY(buttons_copy, buttons);
--- a/src/gui_w32.c
+++ b/src/gui_w32.c
@@ -3120,7 +3120,7 @@ logfont2name(LOGFONTW lf)
     charset_name = charset_id2name((int)lf.lfCharSet);
     quality_name = quality_id2name((int)lf.lfQuality);
 
-    res = (char *)alloc(strlen(font_name) + 30
+    res = alloc(strlen(font_name) + 30
 		    + (charset_name == NULL ? 0 : strlen(charset_name) + 2)
 		    + (quality_name == NULL ? 0 : strlen(quality_name) + 2));
     if (res != NULL)
@@ -3639,7 +3639,7 @@ gui_mch_browsedir(char_u *title, char_u 
 
     reset_VIsual();
 
-    fnames = (char_u **)alloc(cFiles * sizeof(char_u *));
+    fnames = ALLOC_MULT(char_u *, cFiles);
 
     if (fnames != NULL)
 	for (i = 0; i < cFiles; ++i)
@@ -4916,7 +4916,7 @@ gui_mch_do_spawn(char_u *arg)
 	if (wsession == NULL)
 	    goto error;
 	len = (int)wcslen(wsession) * 2 + 27 + 1;
-	cmd = (LPWSTR)alloc(len * (int)sizeof(WCHAR));
+	cmd = ALLOC_MULT(WCHAR, len);
 	if (cmd == NULL)
 	{
 	    vim_free(wsession);
@@ -4942,7 +4942,7 @@ gui_mch_do_spawn(char_u *arg)
 
     // Set up the new command line.
     len = (int)wcslen(name) + (int)wcslen(cmd) + (int)wcslen(warg) + 4;
-    newcmd = (LPWSTR)alloc(len * (int)sizeof(WCHAR));
+    newcmd = ALLOC_MULT(WCHAR, len);
     if (newcmd == NULL)
 	goto error;
     _snwprintf(newcmd, len, L"\"%s\"%s %s", name, cmd, warg);
@@ -5293,11 +5293,9 @@ gui_mch_init(void)
 
     /* Initialise the struct */
     s_findrep_struct.lStructSize = sizeof(s_findrep_struct);
-    s_findrep_struct.lpstrFindWhat =
-			      (LPWSTR)alloc(MSWIN_FR_BUFSIZE * sizeof(WCHAR));
+    s_findrep_struct.lpstrFindWhat = ALLOC_MULT(WCHAR, MSWIN_FR_BUFSIZE);
     s_findrep_struct.lpstrFindWhat[0] = NUL;
-    s_findrep_struct.lpstrReplaceWith =
-			      (LPWSTR)alloc(MSWIN_FR_BUFSIZE * sizeof(WCHAR));
+    s_findrep_struct.lpstrReplaceWith = ALLOC_MULT(WCHAR, MSWIN_FR_BUFSIZE);
     s_findrep_struct.lpstrReplaceWith[0] = NUL;
     s_findrep_struct.wFindWhatLen = MSWIN_FR_BUFSIZE;
     s_findrep_struct.wReplaceWithLen = MSWIN_FR_BUFSIZE;
@@ -5613,7 +5611,7 @@ GetCompositionString_inUCS2(HIMC hIMC, D
     if (ret > 0)
     {
 	/* Allocate the requested buffer plus space for the NUL character. */
-	wbuf = (LPWSTR)alloc(ret + sizeof(WCHAR));
+	wbuf = alloc(ret + sizeof(WCHAR));
 	if (wbuf != NULL)
 	{
 	    pImmGetCompositionStringW(hIMC, GCS, wbuf, ret);
@@ -6058,7 +6056,7 @@ gui_mch_draw_string(
 
 	/* Don't give an out-of-memory message here, it would call us
 	 * recursively. */
-	padding = (int *)lalloc(pad_size * sizeof(int), FALSE);
+	padding = LALLOC_MULT(sizeof(int), pad_size);
 	if (padding != NULL)
 	    for (i = 0; i < pad_size; i++)
 		padding[i] = gui.char_width;
@@ -6095,10 +6093,10 @@ gui_mch_draw_string(
 	    && (unicodebuf == NULL || len > unibuflen))
     {
 	vim_free(unicodebuf);
-	unicodebuf = (WCHAR *)lalloc(len * sizeof(WCHAR), FALSE);
+	unicodebuf = LALLOC_MULT(WCHAR, len);
 
 	vim_free(unicodepdy);
-	unicodepdy = (int *)lalloc(len * sizeof(int), FALSE);
+	unicodepdy = LALLOC_MULT(int, len);
 
 	unibuflen = len;
     }
@@ -6654,7 +6652,7 @@ dialog_callback(
 	/* If the edit box exists, copy the string. */
 	if (s_textfield != NULL)
 	{
-	    WCHAR  *wp = (WCHAR *)alloc(IOSIZE * sizeof(WCHAR));
+	    WCHAR  *wp = ALLOC_MULT(WCHAR, IOSIZE);
 	    char_u *p;
 
 	    GetDlgItemTextW(hwnd, DLG_NONBUTTON_CONTROL + 2, wp, IOSIZE);
@@ -6803,12 +6801,12 @@ gui_mch_dialog(
 	dfltbutton = -1;
 
     /* Allocate array to hold the width of each button */
-    buttonWidths = (int *)alloc(numButtons * sizeof(int));
+    buttonWidths = ALLOC_MULT(int, numButtons);
     if (buttonWidths == NULL)
 	return -1;
 
     /* Allocate array to hold the X position of each button */
-    buttonPositions = (int *)alloc(numButtons * sizeof(int));
+    buttonPositions = ALLOC_MULT(int, numButtons);
     if (buttonPositions == NULL)
 	return -1;
 
@@ -8232,8 +8230,7 @@ gui_mch_register_sign(char_u *signfile)
     }
 
     psign = NULL;
-    if (sign.hImage && (psign = (signicon_t *)alloc(sizeof(signicon_t)))
-								      != NULL)
+    if (sign.hImage && (psign = ALLOC_ONE(signicon_t)) != NULL)
 	*psign = sign;
 
     if (!psign)
@@ -8361,7 +8358,7 @@ make_tooltip(BalloonEval *beval, char *t
     else
 	ToolInfoSize = sizeof(TOOLINFOW);
 
-    pti = (TOOLINFOW *)alloc(ToolInfoSize);
+    pti = alloc(ToolInfoSize);
     if (pti == NULL)
 	return;
 
@@ -8532,7 +8529,7 @@ gui_mch_create_beval_area(
 	return NULL;
     }
 
-    beval = (BalloonEval *)alloc_clear(sizeof(BalloonEval));
+    beval = ALLOC_CLEAR_ONE(BalloonEval);
     if (beval != NULL)
     {
 	beval->target = s_textArea;
--- a/src/gui_x11.c
+++ b/src/gui_x11.c
@@ -1167,7 +1167,7 @@ gui_mch_prepare(int *argc, char **argv)
      * Move all the entries in argv which are relevant to X into gui_argv.
      */
     gui_argc = 0;
-    gui_argv = (char **)lalloc(*argc * sizeof(char *), FALSE);
+    gui_argv = LALLOC_MULT(char *, *argc);
     if (gui_argv == NULL)
 	return;
     gui_argv[gui_argc++] = argv[0];
--- a/src/hardcopy.c
+++ b/src/hardcopy.c
@@ -186,7 +186,7 @@ parse_list_options(
     int		len;
 
     /* Save the old values, so that they can be restored in case of an error. */
-    old_opts = (option_table_T *)alloc(sizeof(option_table_T) * table_size);
+    old_opts = ALLOC_MULT(option_table_T, table_size);
     if (old_opts == NULL)
 	return NULL;
 
@@ -2236,7 +2236,7 @@ prt_build_cid_fontname(int font, char_u 
 {
     char    *fontname;
 
-    fontname = (char *)alloc(name_len + 1);
+    fontname = alloc(name_len + 1);
     if (fontname == NULL)
 	return FALSE;
     vim_strncpy((char_u *)fontname, name, name_len);
--- a/src/hashtab.c
+++ b/src/hashtab.c
@@ -51,7 +51,7 @@ hash_create(void)
 {
     hashtab_T *ht;
 
-    ht = (hashtab_T *)alloc(sizeof(hashtab_T));
+    ht = ALLOC_ONE(hashtab_T);
     if (ht != NULL)
 	hash_init(ht);
     return ht;
@@ -400,7 +400,7 @@ hash_may_resize(
     else
     {
 	/* Allocate an array. */
-	newarray = (hashitem_T *)alloc(sizeof(hashitem_T) * newsize);
+	newarray = ALLOC_MULT(hashitem_T, newsize);
 	if (newarray == NULL)
 	{
 	    /* Out of memory.  When there are NULL items still return OK.
--- a/src/if_cscope.c
+++ b/src/if_cscope.c
@@ -466,7 +466,7 @@ cs_add(exarg_T *eap UNUSED)
 cs_stat_emsg(char *fname)
 {
     char *stat_emsg = _("E563: stat(%s) error: %d");
-    char *buf = (char *)alloc(strlen(stat_emsg) + MAXPATHL + 10);
+    char *buf = alloc(strlen(stat_emsg) + MAXPATHL + 10);
 
     if (buf != NULL)
     {
@@ -503,7 +503,7 @@ cs_add_common(
 #endif
 
     /* get the filename (arg1), expand it, and try to stat it */
-    if ((fname = (char *)alloc(MAXPATHL + 1)) == NULL)
+    if ((fname = alloc(MAXPATHL + 1)) == NULL)
 	goto add_err;
 
     expand_env((char_u *)arg1, (char_u *)fname, MAXPATHL);
@@ -531,7 +531,7 @@ staterr:
     {
 	stat_T	    statbuf2;
 
-	if ((ppath = (char *)alloc(MAXPATHL + 1)) == NULL)
+	if ((ppath = alloc(MAXPATHL + 1)) == NULL)
 	    goto add_err;
 
 	expand_env((char_u *)arg2, (char_u *)ppath, MAXPATHL);
@@ -543,7 +543,7 @@ staterr:
     /* if filename is a directory, append the cscope database name to it */
     if (S_ISDIR(statbuf.st_mode))
     {
-	fname2 = (char *)alloc(strlen(CSCOPE_DBFILE) + strlen(fname) + 2);
+	fname2 = alloc(strlen(CSCOPE_DBFILE) + strlen(fname) + 2);
 	if (fname2 == NULL)
 	    goto add_err;
 
@@ -665,7 +665,7 @@ cs_cnt_matches(int idx)
     char *buf;
     int nlines = 0;
 
-    buf = (char *)alloc(CSREAD_BUFSIZE);
+    buf = alloc(CSREAD_BUFSIZE);
     if (buf == NULL)
 	return 0;
     for (;;)
@@ -769,7 +769,7 @@ cs_create_cmd(char *csoption, char *patt
 	while VIM_ISWHITE(*pat)
 	    ++pat;
 
-    if ((cmd = (char *)alloc(strlen(pat) + 2)) == NULL)
+    if ((cmd = alloc(strlen(pat) + 2)) == NULL)
 	return NULL;
 
     (void)sprintf(cmd, "%d%s", search, pat);
@@ -869,7 +869,7 @@ err_closing:
 	}
 #endif
 	/* expand the cscope exec for env var's */
-	if ((prog = (char *)alloc(MAXPATHL + 1)) == NULL)
+	if ((prog = alloc(MAXPATHL + 1)) == NULL)
 	{
 #ifdef UNIX
 	    return CSCOPE_FAILURE;
@@ -885,7 +885,7 @@ err_closing:
 	if (csinfo[i].ppath)
 	{
 	    /* expand the prepend path for env var's */
-	    if ((ppath = (char *)alloc(MAXPATHL + 1)) == NULL)
+	    if ((ppath = alloc(MAXPATHL + 1)) == NULL)
 	    {
 		vim_free(prog);
 #ifdef UNIX
@@ -903,7 +903,7 @@ err_closing:
 	if (csinfo[i].flags)
 	    len += (int)strlen(csinfo[i].flags);
 
-	if ((cmd = (char *)alloc(len)) == NULL)
+	if ((cmd = alloc(len)) == NULL)
 	{
 	    vim_free(prog);
 	    vim_free(ppath);
@@ -1121,7 +1121,7 @@ cs_find_common(
 	if (strchr(CSQF_FLAGS, *qfpos) == NULL)
 	{
 	    char *nf = _("E469: invalid cscopequickfix flag %c for %c");
-	    char *buf = (char *)alloc(strlen(nf));
+	    char *buf = alloc(strlen(nf));
 
 	    /* strlen will be enough because we use chars */
 	    if (buf != NULL)
@@ -1150,7 +1150,7 @@ cs_find_common(
     if (cmd == NULL)
 	return FALSE;
 
-    nummatches = (int *)alloc(sizeof(int)*csinfo_size);
+    nummatches = ALLOC_MULT(int, csinfo_size);
     if (nummatches == NULL)
     {
 	vim_free(cmd);
@@ -1192,7 +1192,7 @@ cs_find_common(
 	    return FALSE;
 	}
 
-	buf = (char *)alloc(strlen(opt) + strlen(pat) + strlen(nf));
+	buf = alloc(strlen(opt) + strlen(pat) + strlen(nf));
 	if (buf == NULL)
 	    (void)emsg(nf);
 	else
@@ -1429,7 +1429,7 @@ cs_insert_filelist(
 	     * be enough for most users.  If more is needed, csinfo will be
 	     * reallocated. */
 	    csinfo_size = 1;
-	    csinfo = (csinfo_T *)alloc_clear(sizeof(csinfo_T));
+	    csinfo = ALLOC_CLEAR_ONE(csinfo_T);
 	}
 	else
 	{
@@ -1450,14 +1450,14 @@ cs_insert_filelist(
 	    clear_csinfo(j);
     }
 
-    if ((csinfo[i].fname = (char *)alloc(strlen(fname)+1)) == NULL)
+    if ((csinfo[i].fname = alloc(strlen(fname)+1)) == NULL)
 	return -1;
 
     (void)strcpy(csinfo[i].fname, (const char *)fname);
 
     if (ppath != NULL)
     {
-	if ((csinfo[i].ppath = (char *)alloc(strlen(ppath) + 1)) == NULL)
+	if ((csinfo[i].ppath = alloc(strlen(ppath) + 1)) == NULL)
 	{
 	    VIM_CLEAR(csinfo[i].fname);
 	    return -1;
@@ -1468,7 +1468,7 @@ cs_insert_filelist(
 
     if (flags != NULL)
     {
-	if ((csinfo[i].flags = (char *)alloc(strlen(flags) + 1)) == NULL)
+	if ((csinfo[i].flags = alloc(strlen(flags) + 1)) == NULL)
 	{
 	    VIM_CLEAR(csinfo[i].fname);
 	    VIM_CLEAR(csinfo[i].ppath);
@@ -1635,7 +1635,7 @@ cs_make_vim_style_matches(
     if (search != NULL)
     {
 	amt = (int)(strlen(fname) + strlen(slno) + strlen(tagstr) + strlen(search)+6);
-	if ((buf = (char *)alloc(amt)) == NULL)
+	if ((buf = alloc(amt)) == NULL)
 	    return NULL;
 
 	(void)sprintf(buf, "%s\t%s\t%s;\"\t%s", tagstr, fname, slno, search);
@@ -1643,7 +1643,7 @@ cs_make_vim_style_matches(
     else
     {
 	amt = (int)(strlen(fname) + strlen(slno) + strlen(tagstr) + 5);
-	if ((buf = (char *)alloc(amt)) == NULL)
+	if ((buf = alloc(amt)) == NULL)
 	    return NULL;
 
 	(void)sprintf(buf, "%s\t%s\t%s;\"", tagstr, fname, slno);
@@ -1805,7 +1805,7 @@ cs_file_results(FILE *f, int *nummatches
     char *cntx;
     char *context;
 
-    buf = (char *)alloc(CSREAD_BUFSIZE);
+    buf = alloc(CSREAD_BUFSIZE);
     if (buf == NULL)
 	return;
 
@@ -1820,7 +1820,7 @@ cs_file_results(FILE *f, int *nummatches
 			   &slno, &search)) == NULL)
 	       continue;
 
-	   context = (char *)alloc(strlen(cntx)+5);
+	   context = alloc(strlen(cntx)+5);
 	   if (context == NULL)
 	       continue;
 
@@ -1870,13 +1870,13 @@ cs_fill_results(
 
     assert(totmatches > 0);
 
-    buf = (char *)alloc(CSREAD_BUFSIZE);
+    buf = alloc(CSREAD_BUFSIZE);
     if (buf == NULL)
 	return;
 
-    if ((matches = (char **)alloc(sizeof(char *) * totmatches)) == NULL)
+    if ((matches = ALLOC_MULT(char *, totmatches)) == NULL)
 	goto parse_out;
-    if ((cntxts = (char **)alloc(sizeof(char *) * totmatches)) == NULL)
+    if ((cntxts = ALLOC_MULT(char *, totmatches)) == NULL)
 	goto parse_out;
 
     for (i = 0; i < csinfo_size; i++)
@@ -1975,7 +1975,7 @@ cs_print_tags_priv(char **matches, char 
 
     assert(num_matches > 0);
 
-    if ((tbuf = (char *)alloc(strlen(matches[0]) + 1)) == NULL)
+    if ((tbuf = alloc(strlen(matches[0]) + 1)) == NULL)
 	return;
 
     strcpy(tbuf, matches[0]);
@@ -1987,7 +1987,7 @@ cs_print_tags_priv(char **matches, char 
     }
 
     newsize = (int)(strlen(cstag_msg) + strlen(ptag));
-    buf = (char *)alloc(newsize);
+    buf = alloc(newsize);
     if (buf != NULL)
     {
 	bufsize = newsize;
@@ -2010,7 +2010,7 @@ cs_print_tags_priv(char **matches, char 
 	 * by parsing matches[i] on the fly and placing stuff into buf
 	 * directly, but that's too much of a hassle
 	 */
-	if ((tbuf = (char *)alloc(strlen(matches[idx]) + 1)) == NULL)
+	if ((tbuf = alloc(strlen(matches[idx]) + 1)) == NULL)
 	    continue;
 	(void)strcpy(tbuf, matches[idx]);
 
@@ -2030,7 +2030,7 @@ cs_print_tags_priv(char **matches, char 
 	if (bufsize < newsize)
 	{
 	    t_buf = buf;
-	    buf = (char *)vim_realloc(buf, newsize);
+	    buf = vim_realloc(buf, newsize);
 	    if (buf == NULL)
 	    {
 		bufsize = 0;
@@ -2058,7 +2058,7 @@ cs_print_tags_priv(char **matches, char 
 	if (bufsize < newsize)
 	{
 	    t_buf = buf;
-	    buf = (char *)vim_realloc(buf, newsize);
+	    buf = vim_realloc(buf, newsize);
 	    if (buf == NULL)
 	    {
 		bufsize = 0;
@@ -2129,7 +2129,7 @@ cs_read_prompt(int i)
 	    if (bufpos < maxlen - 1 && vim_isprintc(ch))
 	    {
 		if (buf == NULL) /* lazy buffer allocation */
-		    buf = (char *)alloc(maxlen);
+		    buf = alloc(maxlen);
 		if (buf != NULL)
 		{
 		    /* append character to the message */
@@ -2339,9 +2339,9 @@ cs_reset(exarg_T *eap UNUSED)
 	return CSCOPE_SUCCESS;
 
     /* malloc our db and ppath list */
-    dblist = (char **)alloc(csinfo_size * sizeof(char *));
-    pplist = (char **)alloc(csinfo_size * sizeof(char *));
-    fllist = (char **)alloc(csinfo_size * sizeof(char *));
+    dblist = ALLOC_MULT(char *, csinfo_size);
+    pplist = ALLOC_MULT(char *, csinfo_size);
+    fllist = ALLOC_MULT(char *, csinfo_size);
     if (dblist == NULL || pplist == NULL || fllist == NULL)
     {
 	vim_free(dblist);
@@ -2438,7 +2438,7 @@ cs_resolve_file(int i, char *name)
 #endif
        )
     {
-	if ((fullname = (char *)alloc(len)) != NULL)
+	if ((fullname = alloc(len)) != NULL)
 	    (void)sprintf(fullname, "%s/%s", csinfo[i].ppath, name);
     }
     else if (csdir != NULL && csinfo[i].fname != NULL && *csdir != NUL)
--- a/src/if_mzsch.c
+++ b/src/if_mzsch.c
@@ -2582,7 +2582,7 @@ set_buffer_line_list(void *data, int arg
 	    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 @@ insert_buffer_line_list(void *data, int 
 	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 @@ string_to_line(Scheme_Object *obj)
     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 @@ mzscheme_to_vim_impl(Scheme_Object *obj,
 	    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 @@ mzscheme_to_vim_impl(Scheme_Object *obj,
 	    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 @@ vim_funcref(void *name, int argc, Scheme
 	++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
--- a/src/if_perlsfio.c
+++ b/src/if_perlsfio.c
@@ -51,7 +51,7 @@ sfdcnewvim(void)
 {
     Sfdisc_t	*disc;
 
-    disc = (Sfdisc_t *)alloc(sizeof(Sfdisc_t));
+    disc = ALLOC_ONE(Sfdisc_t);
     if (disc == NULL)
 	return NULL;
 
--- a/src/if_py_both.h
+++ b/src/if_py_both.h
@@ -3138,8 +3138,7 @@ set_partial(FunctionObject *self, partia
 	pt->pt_argc = self->argc;
 	if (exported)
 	{
-	    pt->pt_argv = (typval_T *)alloc_clear(
-						sizeof(typval_T) * self->argc);
+	    pt->pt_argv = ALLOC_CLEAR_MULT(typval_T, self->argc);
 	    for (i = 0; i < pt->pt_argc; ++i)
 		copy_tv(&self->argv[i], &pt->pt_argv[i]);
 	}
@@ -4262,7 +4261,7 @@ StringToLine(PyObject *obj)
     /* Create a copy of the string, with internal nulls replaced by
      * newline characters, as is the vim convention.
      */
-    save = (char *)alloc(len+1);
+    save = alloc(len+1);
     if (save == NULL)
     {
 	PyErr_NoMemory();
@@ -6243,7 +6242,8 @@ ConvertFromPyObject(PyObject *obj, typva
 	FunctionObject *func = (FunctionObject *) obj;
 	if (func->self != NULL || func->argv != NULL)
 	{
-	    partial_T *pt = (partial_T *)alloc_clear(sizeof(partial_T));
+	    partial_T *pt = ALLOC_CLEAR_ONE(partial_T);
+
 	    set_partial(func, pt, TRUE);
 	    tv->vval.v_partial = pt;
 	    tv->v_type = VAR_PARTIAL;
--- a/src/if_python3.c
+++ b/src/if_python3.c
@@ -877,7 +877,7 @@ Python3_Init(void)
 	    size_t len = mbstowcs(NULL, (char *)p_py3home, 0) + 1;
 
 	    /* The string must not change later, make a copy in static memory. */
-	    py_home_buf = (wchar_t *)alloc(len * sizeof(wchar_t));
+	    py_home_buf = ALLOC_MULT(wchar_t, len);
 	    if (py_home_buf != NULL && mbstowcs(
 			    py_home_buf, (char *)p_py3home, len) != (size_t)-1)
 		Py_SetPythonHome(py_home_buf);
@@ -1629,7 +1629,7 @@ LineToString(const char *str)
     Py_ssize_t len = strlen(str);
     char *tmp,*p;
 
-    tmp = (char *)alloc(len + 1);
+    tmp = alloc(len + 1);
     p = tmp;
     if (p == NULL)
     {
--- a/src/if_xcmdsrv.c
+++ b/src/if_xcmdsrv.c
@@ -441,7 +441,7 @@ serverSendToVim(
      * Length must be computed exactly!
      */
     length = STRLEN(name) + STRLEN(p_enc) + STRLEN(cmd) + 14;
-    property = (char_u *)alloc(length + 30);
+    property = alloc(length + 30);
 
     sprintf((char *)property, "%c%c%c-n %s%c-E %s%c-s %s",
 		      0, asExpr ? 'c' : 'k', 0, name, 0, p_enc, 0, cmd);
@@ -750,7 +750,7 @@ serverSendReply(char_u *name, char_u *st
 	return -1;
 
     length = STRLEN(p_enc) + STRLEN(str) + 14;
-    if ((property = (char_u *)alloc(length + 30)) != NULL)
+    if ((property = alloc(length + 30)) != NULL)
     {
 	sprintf((char *)property, "%cn%c-E %s%c-n %s%c-w %x",
 			    0, 0, p_enc, 0, str, 0, (unsigned int)commWindow);
@@ -1157,7 +1157,7 @@ save_in_queue(char_u *propInfo, long_u l
 {
     x_queue_T *node;
 
-    node = (x_queue_T *)alloc(sizeof(x_queue_T));
+    node = ALLOC_ONE(x_queue_T);
     if (node == NULL)
 	return;	    /* out of memory */
     node->propInfo = propInfo;
--- a/src/insexpand.c
+++ b/src/insexpand.c
@@ -473,7 +473,7 @@ ins_compl_add_infercase(
 					   ? actual_len : actual_compl_length;
 
 	// Allocate wide character array for the completion and fill it.
-	wca = (int *)alloc(actual_len * sizeof(int));
+	wca = ALLOC_MULT(int, actual_len);
 	if (wca != NULL)
 	{
 	    p = str;
@@ -611,7 +611,7 @@ ins_compl_add(
 
     // Allocate a new match structure.
     // Copy the values to the new match structure.
-    match = (compl_T *)alloc_clear(sizeof(compl_T));
+    match = ALLOC_CLEAR_ONE(compl_T);
     if (match == NULL)
 	return FAIL;
     match->cp_number = -1;
@@ -1070,8 +1070,7 @@ ins_compl_show_pum(void)
 	} while (compl != NULL && compl != compl_first_match);
 	if (compl_match_arraysize == 0)
 	    return;
-	compl_match_array = (pumitem_T *)alloc_clear(
-				    sizeof(pumitem_T) * compl_match_arraysize);
+	compl_match_array = ALLOC_CLEAR_MULT(pumitem_T, compl_match_arraysize);
 	if (compl_match_array != NULL)
 	{
 	    // If the current match is the original text don't find the first
--- a/src/list.c
+++ b/src/list.c
@@ -72,7 +72,7 @@ list_alloc(void)
 {
     list_T  *l;
 
-    l = (list_T *)alloc_clear(sizeof(list_T));
+    l = ALLOC_CLEAR_ONE(list_T);
     if (l != NULL)
     {
 	/* Prepend the list to the list of lists for garbage collection. */
@@ -244,7 +244,7 @@ list_free(list_T *l)
     listitem_T *
 listitem_alloc(void)
 {
-    return (listitem_T *)alloc(sizeof(listitem_T));
+    return ALLOC_ONE(listitem_T);
 }
 
 /*
--- a/src/mark.c
+++ b/src/mark.c
@@ -1478,11 +1478,9 @@ static int vi_jumplist_len = 0;
     void
 prepare_viminfo_marks(void)
 {
-    vi_namedfm = (xfmark_T *)alloc_clear((NMARKS + EXTRA_MARKS)
-						     * (int)sizeof(xfmark_T));
+    vi_namedfm = ALLOC_CLEAR_MULT(xfmark_T, NMARKS + EXTRA_MARKS);
 #ifdef FEAT_JUMPLIST
-    vi_jumplist = (xfmark_T *)alloc_clear(JUMPLISTSIZE
-						     * (int)sizeof(xfmark_T));
+    vi_jumplist = ALLOC_CLEAR_MULT(xfmark_T, JUMPLISTSIZE);
     vi_jumplist_len = 0;
 #endif
 }
--- a/src/mbyte.c
+++ b/src/mbyte.c
@@ -6897,7 +6897,7 @@ string_convert_ext(
 		    return retval;
 		}
 	    }
-	    tmp = (short_u *)alloc(sizeof(short_u) * tmp_len);
+	    tmp = ALLOC_MULT(short_u, tmp_len);
 	    if (tmp == NULL)
 		break;
 	    if (vcp->vc_cpfrom == 0)
--- a/src/memfile.c
+++ b/src/memfile.c
@@ -130,7 +130,7 @@ mf_open(char_u *fname, int flags)
     struct STATFS	stf;
 #endif
 
-    if ((mfp = (memfile_T *)alloc(sizeof(memfile_T))) == NULL)
+    if ((mfp = ALLOC_ONE(memfile_T)) == NULL)
 	return NULL;
 
     if (fname == NULL)	    /* no file for this memfile, use memory only */
@@ -362,7 +362,7 @@ mf_new(memfile_T *mfp, int negative, int
 	}
 	else if (hp == NULL)	    /* need to allocate memory for this block */
 	{
-	    if ((p = (char_u *)alloc(mfp->mf_page_size * page_count)) == NULL)
+	    if ((p = alloc(mfp->mf_page_size * page_count)) == NULL)
 		return NULL;
 	    hp = mf_rem_free(mfp);
 	    hp->bh_data = p;
@@ -893,10 +893,9 @@ mf_alloc_bhdr(memfile_T *mfp, int page_c
 {
     bhdr_T	*hp;
 
-    if ((hp = (bhdr_T *)alloc(sizeof(bhdr_T))) != NULL)
+    if ((hp = ALLOC_ONE(bhdr_T)) != NULL)
     {
-	if ((hp->bh_data = (char_u *)alloc(mfp->mf_page_size * page_count))
-								      == NULL)
+	if ((hp->bh_data = alloc(mfp->mf_page_size * page_count)) == NULL)
 	{
 	    vim_free(hp);	    /* not enough memory */
 	    return NULL;
@@ -1131,7 +1130,7 @@ mf_trans_add(memfile_T *mfp, bhdr_T *hp)
     if (hp->bh_bnum >= 0)		    /* it's already positive */
 	return OK;
 
-    if ((np = (NR_TRANS *)alloc(sizeof(NR_TRANS))) == NULL)
+    if ((np = ALLOC_ONE(NR_TRANS)) == NULL)
 	return FAIL;
 
 /*
@@ -1460,7 +1459,7 @@ mf_hash_grow(mf_hashtab_T *mht)
     size_t	    size;
 
     size = (mht->mht_mask + 1) * MHT_GROWTH_FACTOR * sizeof(void *);
-    buckets = (mf_hashitem_T **)lalloc_clear(size, FALSE);
+    buckets = lalloc_clear(size, FALSE);
     if (buckets == NULL)
 	return FAIL;
 
--- a/src/memfile_test.c
+++ b/src/memfile_test.c
@@ -67,7 +67,7 @@ test_mf_hash(void)
 	assert(mf_hash_find(&ht, key) == NULL);
 
 	/* allocate and add new item */
-	item = (mf_hashitem_T *)lalloc_clear(sizeof(mf_hashtab_T), FALSE);
+	item = LALLOC_CLEAR_ONE(mf_hashtab_T);
 	assert(item != NULL);
 	item->mhi_key = key;
 	mf_hash_add_item(&ht, item);
--- a/src/memline.c
+++ b/src/memline.c
@@ -1189,7 +1189,7 @@ ml_recover(int checkext)
      * Allocate a buffer structure for the swap file that is used for recovery.
      * Only the memline and crypt information in it are really used.
      */
-    buf = (buf_T *)alloc(sizeof(buf_T));
+    buf = ALLOC_ONE(buf_T);
     if (buf == NULL)
 	goto theend;
 
@@ -1911,9 +1911,9 @@ recover_names(
 			      );
 	    if (swapname != NULL)
 	    {
-		if (mch_stat((char *)swapname, &st) != -1)	    /* It exists! */
+		if (mch_stat((char *)swapname, &st) != -1)    // It exists!
 		{
-		    files = (char_u **)alloc(sizeof(char_u *));
+		    files = ALLOC_ONE(char_u *);
 		    if (files != NULL)
 		    {
 			files[0] = swapname;
@@ -4205,8 +4205,7 @@ ml_add_stack(buf_T *buf)
     {
 	CHECK(top > 0, _("Stack size increases")); /* more than 5 levels??? */
 
-	newstack = (infoptr_T *)alloc(sizeof(infoptr_T) *
-					(buf->b_ml.ml_stack_size + STACK_INCR));
+	newstack = ALLOC_MULT(infoptr_T, buf->b_ml.ml_stack_size + STACK_INCR);
 	if (newstack == NULL)
 	    return -1;
 	if (top > 0)
@@ -5235,7 +5234,7 @@ ml_encrypt_data(
     if (state == NULL)
 	return data;
 
-    new_data = (char_u *)alloc(size);
+    new_data = alloc(size);
     if (new_data == NULL)
 	return NULL;
     head_end = (char_u *)(&dp->db_index[dp->db_line_count]);
@@ -5375,8 +5374,7 @@ ml_updatechunk(
 	return;
     if (buf->b_ml.ml_chunksize == NULL)
     {
-	buf->b_ml.ml_chunksize =
-			       (chunksize_T *)alloc(sizeof(chunksize_T) * 100);
+	buf->b_ml.ml_chunksize = ALLOC_MULT(chunksize_T, 100);
 	if (buf->b_ml.ml_chunksize == NULL)
 	{
 	    buf->b_ml.ml_usedchunks = -1;
--- a/src/message.c
+++ b/src/message.c
@@ -875,7 +875,7 @@ add_msg_hist(
 	(void)delete_first_msg();
 
     /* allocate an entry and add the message at the end of the history */
-    p = (struct msg_hist *)alloc(sizeof(struct msg_hist));
+    p = ALLOC_ONE(struct msg_hist);
     if (p != NULL)
     {
 	if (len < 0)
@@ -2360,7 +2360,7 @@ store_sb_text(
 
     if (s > *sb_str)
     {
-	mp = (msgchunk_T *)alloc(sizeof(msgchunk_T) + (s - *sb_str));
+	mp = alloc(sizeof(msgchunk_T) + (s - *sb_str));
 	if (mp != NULL)
 	{
 	    mp->sb_eol = finish;
--- a/src/misc2.c
+++ b/src/misc2.c
@@ -821,7 +821,7 @@ alloc_does_fail(size_t size)
  * The normal way to allocate memory.  This handles an out-of-memory situation
  * as well as possible, still returns NULL when we're completely out.
  */
-    char_u *
+    void *
 alloc(size_t size)
 {
     return lalloc(size, TRUE);
@@ -830,7 +830,7 @@ alloc(size_t size)
 /*
  * alloc() with an ID for alloc_fail().
  */
-    char_u *
+    void *
 alloc_id(size_t size, alloc_id_T id UNUSED)
 {
 #ifdef FEAT_EVAL
@@ -843,10 +843,10 @@ alloc_id(size_t size, alloc_id_T id UNUS
 /*
  * Allocate memory and set all bytes to zero.
  */
-    char_u *
+    void *
 alloc_clear(size_t size)
 {
-    char_u *p;
+    void *p;
 
     p = lalloc(size, TRUE);
     if (p != NULL)
@@ -857,7 +857,7 @@ alloc_clear(size_t size)
 /*
  * Same as alloc_clear() but with allocation id for testing
  */
-    char_u *
+    void *
 alloc_clear_id(size_t size, alloc_id_T id UNUSED)
 {
 #ifdef FEAT_EVAL
@@ -870,12 +870,12 @@ alloc_clear_id(size_t size, alloc_id_T i
 /*
  * Allocate memory like lalloc() and set all bytes to zero.
  */
-    char_u *
+    void *
 lalloc_clear(size_t size, int message)
 {
-    char_u *p;
-
-    p = (lalloc(size, message));
+    void *p;
+
+    p = lalloc(size, message);
     if (p != NULL)
 	(void)vim_memset(p, 0, size);
     return p;
@@ -885,10 +885,10 @@ lalloc_clear(size_t size, int message)
  * Low level memory allocation function.
  * This is used often, KEEP IT FAST!
  */
-    char_u *
+    void *
 lalloc(size_t size, int message)
 {
-    char_u	*p;		    /* pointer to new storage space */
+    void	*p;		    /* pointer to new storage space */
     static int	releasing = FALSE;  /* don't do mf_release_all() recursive */
     int		try_again;
 #if defined(HAVE_AVAIL_MEM)
@@ -921,7 +921,7 @@ lalloc(size_t size, int message)
 	 *    allocating KEEP_ROOM amount of memory.
 	 * 3. Strict check for available memory: call mch_avail_mem()
 	 */
-	if ((p = (char_u *)malloc(size)) != NULL)
+	if ((p = malloc(size)) != NULL)
 	{
 #ifndef HAVE_AVAIL_MEM
 	    /* 1. No check for available memory: Just return. */
@@ -937,7 +937,7 @@ lalloc(size_t size, int message)
 	    /* 3. check for available memory: call mch_avail_mem() */
 	    if (mch_avail_mem(TRUE) < KEEP_ROOM_KB && !releasing)
 	    {
-		free((char *)p);	/* System is low... no go! */
+		free(p);	/* System is low... no go! */
 		p = NULL;
 	    }
 	    else
@@ -965,7 +965,7 @@ lalloc(size_t size, int message)
 
 theend:
 #ifdef MEM_PROFILE
-    mem_post_alloc((void **)&p, size);
+    mem_post_alloc(&p, size);
 #endif
     return p;
 }
@@ -974,7 +974,7 @@ theend:
  * lalloc() with an ID for alloc_fail().
  */
 #if defined(FEAT_SIGNS) || defined(PROTO)
-    char_u *
+    void *
 lalloc_id(size_t size, int message, alloc_id_T id UNUSED)
 {
 #ifdef FEAT_EVAL
@@ -2058,8 +2058,7 @@ ga_grow(garray_T *gap, int n)
 	if (n < gap->ga_growsize)
 	    n = gap->ga_growsize;
 	new_len = gap->ga_itemsize * (gap->ga_len + n);
-	pp = (gap->ga_data == NULL)
-	      ? alloc(new_len) : vim_realloc(gap->ga_data, new_len);
+	pp = vim_realloc(gap->ga_data, new_len);
 	if (pp == NULL)
 	    return FAIL;
 	old_len = gap->ga_itemsize * gap->ga_maxlen;
@@ -4055,7 +4054,7 @@ putenv(const char *string)
 	    if (moreenv() < 0)
 		return -1;
 	}
-	p = (char *)alloc(strlen(string) + 1);
+	p = alloc(strlen(string) + 1);
 	if (p == NULL)		/* not enough core */
 	    return -1;
 	environ[i + 1] = 0;	/* new end of env. */
@@ -4103,13 +4102,13 @@ newenv(void)
 	;
 
     esize = i + EXTRASIZE + 1;
-    env = (char **)alloc(esize * sizeof (elem));
+    env = ALLOC_MULT(char *, esize);
     if (env == NULL)
 	return -1;
 
     for (i = 0; environ[i]; i++)
     {
-	elem = (char *)alloc(strlen(environ[i]) + 1);
+	elem = alloc(strlen(environ[i]) + 1);
 	if (elem == NULL)
 	    return -1;
 	env[i] = elem;
@@ -4129,7 +4128,7 @@ moreenv(void)
     char    **env;
 
     esize = envsize + EXTRASIZE;
-    env = (char **)vim_realloc((char *)environ, esize * sizeof (*env));
+    env = vim_realloc((char *)environ, esize * sizeof (*env));
     if (env == 0)
 	return -1;
     environ = env;
@@ -4575,7 +4574,7 @@ mch_parse_cmd(char_u *cmd, int use_shcf,
 		}
 	    }
 
-	    *argv = (char **)alloc((*argc + 4) * sizeof(char *));
+	    *argv = ALLOC_MULT(char *, *argc + 4);
 	    if (*argv == NULL)	    /* out of memory */
 		return FAIL;
 	}
@@ -4622,7 +4621,7 @@ build_argv_from_list(list_T *l, char ***
     char_u	*s;
 
     /* Pass argv[] to mch_call_shell(). */
-    *argv = (char **)alloc(sizeof(char *) * (l->lv_len + 1));
+    *argv = ALLOC_MULT(char *, l->lv_len + 1);
     if (*argv == NULL)
 	return FAIL;
     *argc = 0;
@@ -4667,7 +4666,7 @@ write_session_file(char_u *filename)
     escaped_filename = vim_strsave_escaped(filename, escape_chars);
     if (escaped_filename == NULL)
 	return FALSE;
-    mksession_cmdline = (char *)alloc(10 + (int)STRLEN(escaped_filename) + 1);
+    mksession_cmdline = alloc(10 + (int)STRLEN(escaped_filename) + 1);
     if (mksession_cmdline == NULL)
     {
 	vim_free(escaped_filename);
--- a/src/netbeans.c
+++ b/src/netbeans.c
@@ -321,7 +321,7 @@ postpone_keycommand(char_u *keystr)
 {
     keyQ_T *node;
 
-    node = (keyQ_T *)alloc(sizeof(keyQ_T));
+    node = ALLOC_ONE(keyQ_T);
     if (node == NULL)
 	return;  /* out of memory, drop the key */
 
@@ -667,7 +667,7 @@ nb_get_buf(int bufno)
     if (!buf_list)
     {
 	/* initialize */
-	buf_list = (nbbuf_T *)alloc_clear(100 * sizeof(nbbuf_T));
+	buf_list = alloc_clear(100 * sizeof(nbbuf_T));
 	buf_list_size = 100;
     }
     if (bufno >= buf_list_used) /* new */
@@ -678,8 +678,7 @@ nb_get_buf(int bufno)
 
 	    incr = bufno - buf_list_size + 90;
 	    buf_list_size += incr;
-	    buf_list = (nbbuf_T *)vim_realloc(
-				   buf_list, buf_list_size * sizeof(nbbuf_T));
+	    buf_list = vim_realloc(buf_list, buf_list_size * sizeof(nbbuf_T));
 	    if (buf_list == NULL)
 	    {
 		vim_free(t_buf_list);
@@ -863,7 +862,7 @@ nb_unquote(char_u *p, char_u **endp)
     int done = 0;
 
     /* result is never longer than input */
-    result = (char *)alloc_clear(STRLEN(p) + 1);
+    result = alloc_clear(STRLEN(p) + 1);
     if (result == NULL)
 	return NULL;
 
@@ -2470,7 +2469,7 @@ netbeans_beval_cb(
 	 * length. */
 	if (text != NULL && text[0] != NUL && STRLEN(text) < MAXPATHL)
 	{
-	    buf = (char *)alloc(MAXPATHL * 2 + 25);
+	    buf = alloc(MAXPATHL * 2 + 25);
 	    if (buf != NULL)
 	    {
 		p = nb_quote(text);
@@ -3210,8 +3209,7 @@ addsigntype(
 	    if (globalsignmaplen == 0) /* first allocation */
 	    {
 		globalsignmaplen = 20;
-		globalsignmap = (char **)alloc_clear(
-					    globalsignmaplen * sizeof(char *));
+		globalsignmap = ALLOC_CLEAR_MULT(char *, globalsignmaplen);
 	    }
 	    else    /* grow it */
 	    {
@@ -3221,7 +3219,7 @@ addsigntype(
 
 		globalsignmaplen *= 2;
 		incr = globalsignmaplen - oldlen;
-		globalsignmap = (char **)vim_realloc(globalsignmap,
+		globalsignmap = vim_realloc(globalsignmap,
 					   globalsignmaplen * sizeof(char *));
 		if (globalsignmap == NULL)
 		{
@@ -3248,7 +3246,7 @@ addsigntype(
 	if (buf->signmaplen == 0) /* first allocation */
 	{
 	    buf->signmaplen = 5;
-	    buf->signmap = (int *)alloc_clear(buf->signmaplen * sizeof(int));
+	    buf->signmap = ALLOC_CLEAR_MULT(int, buf->signmaplen);
 	}
 	else    /* grow it */
 	{
@@ -3258,7 +3256,7 @@ addsigntype(
 
 	    buf->signmaplen *= 2;
 	    incr = buf->signmaplen - oldlen;
-	    buf->signmap = (int *)vim_realloc(buf->signmap,
+	    buf->signmap = vim_realloc(buf->signmap,
 					       buf->signmaplen * sizeof(int));
 	    if (buf->signmap == NULL)
 	    {
--- a/src/normal.c
+++ b/src/normal.c
@@ -5655,7 +5655,7 @@ nv_ident(cmdarg_T *cap)
 	    vim_free(buf);
 	    return;
 	}
-	newbuf = (char_u *)vim_realloc(buf, STRLEN(buf) + STRLEN(p) + 1);
+	newbuf = vim_realloc(buf, STRLEN(buf) + STRLEN(p) + 1);
 	if (newbuf == NULL)
 	{
 	    vim_free(buf);
--- a/src/ops.c
+++ b/src/ops.c
@@ -1003,7 +1003,7 @@ get_register(
 #endif
 
     get_yank_register(name, 0);
-    reg = (yankreg_T *)alloc(sizeof(yankreg_T));
+    reg = ALLOC_ONE(yankreg_T);
     if (reg != NULL)
     {
 	*reg = *y_current;
@@ -1013,7 +1013,7 @@ get_register(
 	    if (reg->y_size == 0)
 		reg->y_array = NULL;
 	    else
-		reg->y_array = (char_u **)alloc(sizeof(char_u *) * reg->y_size);
+		reg->y_array = ALLOC_MULT(char_u *, reg->y_size);
 	    if (reg->y_array != NULL)
 	    {
 		for (i = 0; i < reg->y_size; ++i)
@@ -1175,8 +1175,7 @@ stuff_yank(int regname, char_u *p)
     else
     {
 	free_yank_all();
-	if ((y_current->y_array =
-			(char_u **)alloc(sizeof(char_u *))) == NULL)
+	if ((y_current->y_array = ALLOC_ONE(char_u *)) == NULL)
 	{
 	    vim_free(p);
 	    return FAIL;
@@ -3057,8 +3056,7 @@ op_yank(oparg_T *oap, int deleting, int 
     y_current->y_size = yanklines;
     y_current->y_type = yanktype;   /* set the yank register type */
     y_current->y_width = 0;
-    y_current->y_array = (char_u **)lalloc_clear(sizeof(char_u *) * yanklines,
-									 TRUE);
+    y_current->y_array = lalloc_clear(sizeof(char_u *) * yanklines, TRUE);
     if (y_current->y_array == NULL)
     {
 	y_current = curr;
@@ -3171,8 +3169,7 @@ op_yank(oparg_T *oap, int deleting, int 
 
     if (curr != y_current)	/* append the new block to the old block */
     {
-	new_ptr = (char_u **)alloc(sizeof(char_u *) *
-					   (curr->y_size + y_current->y_size));
+	new_ptr = ALLOC_MULT(char_u *, curr->y_size + y_current->y_size);
 	if (new_ptr == NULL)
 	    goto fail;
 	for (j = 0; j < curr->y_size; ++j)
@@ -3354,7 +3351,7 @@ copy_yank_reg(yankreg_T *reg)
     y_current = reg;
     free_yank_all();
     *y_current = *curr;
-    y_current->y_array = (char_u **)lalloc_clear(
+    y_current->y_array = lalloc_clear(
 				    sizeof(char_u *) * y_current->y_size, TRUE);
     if (y_current->y_array == NULL)
 	y_current->y_size = 0;
@@ -3491,7 +3488,7 @@ do_put(
 		}
 		if (y_array != NULL)
 		    break;
-		y_array = (char_u **)alloc((y_size * sizeof(char_u *)));
+		y_array = ALLOC_MULT(char_u *, y_size);
 		if (y_array == NULL)
 		    goto end;
 	    }
@@ -4459,7 +4456,7 @@ do_join(
 #if defined(FEAT_COMMENTS) || defined(PROTO)
     if (remove_comments)
     {
-	comments = (int *)lalloc_clear(count * sizeof(int), TRUE);
+	comments = lalloc_clear(count * sizeof(int), TRUE);
 	if (comments == NULL)
 	{
 	    vim_free(spaces);
@@ -4570,9 +4567,8 @@ do_join(
     {
 	// Allocate an array to copy the text properties of joined lines into.
 	// And another array to store the number of properties in each line.
-	prop_lines = (textprop_T **)alloc_clear(
-					   (count - 1) * sizeof(textprop_T *));
-	prop_lengths = (int *)alloc_clear((count - 1) * sizeof(int));
+	prop_lines = ALLOC_CLEAR_MULT(textprop_T *, count - 1);
+	prop_lengths = ALLOC_CLEAR_MULT(int, count - 1);
 	if (prop_lengths == NULL)
 	    VIM_CLEAR(prop_lines);
     }
@@ -5975,8 +5971,7 @@ static yankreg_T *y_read_regs = NULL;
     void
 prepare_viminfo_registers(void)
 {
-     y_read_regs = (yankreg_T *)alloc_clear(NUM_REGISTERS
-						    * (int)sizeof(yankreg_T));
+     y_read_regs = ALLOC_CLEAR_MULT(yankreg_T, NUM_REGISTERS);
 }
 
     void
@@ -6051,7 +6046,7 @@ read_viminfo_register(vir_T *virp, int f
 	 */
 	if (set_prev)
 	    y_previous = y_current;
-	array = (char_u **)alloc(limit * sizeof(char_u *));
+	array = ALLOC_MULT(char_u *, limit);
 	str = skipwhite(skiptowhite(str));
 	if (STRNCMP(str, "CHAR", 4) == 0)
 	    new_type = MCHAR;
@@ -6112,7 +6107,7 @@ read_viminfo_register(vir_T *virp, int f
 	else
 	{
 	    /* Move the lines from array[] to y_array[]. */
-	    y_current->y_array = (char_u **)alloc(size * sizeof(char_u *));
+	    y_current->y_array = ALLOC_MULT(char_u *, size);
 	    for (i = 0; i < size; i++)
 	    {
 		if (y_current->y_array == NULL)
@@ -6209,7 +6204,7 @@ handle_viminfo_register(garray_T *values
 	y_ptr->y_array = NULL;
 	return;
     }
-    y_ptr->y_array = (char_u **)alloc(linecount * sizeof(char_u *));
+    y_ptr->y_array = ALLOC_MULT(char_u *, linecount);
     if (y_ptr->y_array == NULL)
     {
 	y_ptr->y_size = 0; // ensure object state is consistent
@@ -7100,8 +7095,7 @@ str_to_reg(
      * Allocate an array to hold the pointers to the new register lines.
      * If the register was not empty, move the existing lines to the new array.
      */
-    pp = (char_u **)lalloc_clear((y_ptr->y_size + newlines)
-						    * sizeof(char_u *), TRUE);
+    pp = lalloc_clear((y_ptr->y_size + newlines) * sizeof(char_u *), TRUE);
     if (pp == NULL)	/* out of memory */
 	return;
     for (lnum = 0; lnum < y_ptr->y_size; ++lnum)
--- a/src/option.c
+++ b/src/option.c
@@ -7966,7 +7966,7 @@ skip:
 	wp->w_p_cc_cols = NULL;
     else
     {
-	wp->w_p_cc_cols = (int *)alloc(sizeof(int) * (count + 1));
+	wp->w_p_cc_cols = ALLOC_MULT(int, count + 1);
 	if (wp->w_p_cc_cols != NULL)
 	{
 	    /* sort the columns for faster usage on screen redraw inside
@@ -10106,8 +10106,7 @@ showoptions(
 #define INC 20
 #define GAP 3
 
-    items = (struct vimoption **)alloc(sizeof(struct vimoption *)
-								* PARAM_COUNT);
+    items = ALLOC_MULT(struct vimoption *, PARAM_COUNT);
     if (items == NULL)
 	return;
 
@@ -11998,7 +11997,7 @@ ExpandSettings(
 		*num_file = num_term;
 	    else
 		return OK;
-	    *file = (char_u **)alloc(*num_file * sizeof(char_u *));
+	    *file = ALLOC_MULT(char_u *, *num_file);
 	    if (*file == NULL)
 	    {
 		*file = (char_u **)"";
@@ -12016,7 +12015,7 @@ ExpandOldSetting(int *num_file, char_u *
     char_u  *buf;
 
     *num_file = 0;
-    *file = (char_u **)alloc(sizeof(char_u *));
+    *file = ALLOC_ONE(char_u *);
     if (*file == NULL)
 	return FAIL;
 
@@ -12879,7 +12878,7 @@ tabstop_set(char_u *var, int **array)
 	return FALSE;
     }
 
-    *array = (int *)alloc((valcount + 1) * sizeof(int));
+    *array = ALLOC_MULT(int, valcount + 1);
     if (*array == NULL)
 	return FALSE;
     (*array)[0] = valcount;
@@ -13102,7 +13101,7 @@ tabstop_copy(int *oldts)
 
     if (oldts == NULL)
 	return NULL;
-    newts = (int *)alloc((oldts[0] + 1) * sizeof(int));
+    newts = ALLOC_MULT(int, oldts[0] + 1);
     if (newts != NULL)
 	for (t = 0; t <= oldts[0]; ++t)
 	    newts[t] = oldts[t];
--- a/src/os_amiga.c
+++ b/src/os_amiga.c
@@ -580,7 +580,7 @@ get_fib(char_u *fname)
 #ifdef __amigaos4__
     fib = AllocDosObject(DOS_FIB,0);
 #else
-    fib = (struct FileInfoBlock *)alloc(sizeof(struct FileInfoBlock));
+    fib = ALLOC_ONE(struct FileInfoBlock);
 #endif
     if (fib != NULL)
     {
@@ -1448,7 +1448,7 @@ mch_expandpath(
 #ifdef __amigaos4__
     Anchor = AllocDosObject(DOS_ANCHORPATH, AnchorTags);
 #else
-    Anchor = (struct AnchorPath *)alloc_clear(ANCHOR_SIZE);
+    Anchor = alloc_clear(ANCHOR_SIZE);
 #endif
     if (Anchor == NULL)
 	return 0;
--- a/src/os_mac_conv.c
+++ b/src/os_mac_conv.c
@@ -550,7 +550,7 @@ mac_utf8_to_utf16(
     }
 
     convertRange = CFRangeMake(0, CFStringGetLength(utf8_str));
-    result = (UniChar *)alloc(convertRange.length * sizeof(UniChar));
+    result = ALLOC_MULT(UniChar, convertRange.length);
 
     CFStringGetCharacters(utf8_str, convertRange, result);
 
--- a/src/os_mswin.c
+++ b/src/os_mswin.c
@@ -1801,7 +1801,7 @@ resolve_reparse_point(char_u *fname)
 	goto fail;
 
     size = sizeof(FILE_NAME_INFO_) + sizeof(WCHAR) * (MAX_PATH - 1);
-    nameinfo = (FILE_NAME_INFO_*)alloc(size + sizeof(WCHAR));
+    nameinfo = alloc(size + sizeof(WCHAR));
     if (nameinfo == NULL)
 	goto fail;
 
@@ -1835,7 +1835,7 @@ resolve_reparse_point(char_u *fname)
 	    GetLastError() != ERROR_MORE_DATA)
 	goto fail;
 
-    volnames = (WCHAR*)alloc(size * sizeof(WCHAR));
+    volnames = ALLOC_MULT(WCHAR, size);
     if (!GetVolumePathNamesForVolumeNameW(buff, volnames, size,
 		&size))
 	goto fail;
@@ -3078,7 +3078,7 @@ theend:
     if (ret == OK && printer_dc == NULL)
     {
 	vim_free(lastlf);
-	lastlf = (LOGFONTW *)alloc(sizeof(LOGFONTW));
+	lastlf = ALLOC_ONE(LOGFONTW);
 	if (lastlf != NULL)
 	    mch_memmove(lastlf, lf, sizeof(LOGFONTW));
     }
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -3210,7 +3210,7 @@ mch_early_init(void)
      * Ignore any errors.
      */
 #if defined(HAVE_SIGALTSTACK) || defined(HAVE_SIGSTACK)
-    signal_stack = (char *)alloc(SIGSTKSZ);
+    signal_stack = alloc(SIGSTKSZ);
     init_signal_stack();
 #endif
 }
@@ -6843,7 +6843,7 @@ mch_expand_wildcards(
 	goto notfound;
     }
     *num_file = i;
-    *file = (char_u **)alloc(sizeof(char_u *) * i);
+    *file = ALLOC_MULT(char_u *, i);
     if (*file == NULL)
     {
 	/* out of memory */
@@ -6938,7 +6938,7 @@ save_patterns(
     int		i;
     char_u	*s;
 
-    *file = (char_u **)alloc(num_pat * sizeof(char_u *));
+    *file = ALLOC_MULT(char_u *, num_pat);
     if (*file == NULL)
 	return FAIL;
     for (i = 0; i < num_pat; i++)
--- a/src/os_vms.c
+++ b/src/os_vms.c
@@ -238,14 +238,14 @@ mch_getenv(char_u *lognam)
     if (sys$trnlnm(&attrib, &d_file_dev, &d_lognam, NULL,&itmlst) == SS$_NORMAL)
     {
 	buffer[lengte] = '\0';
-	if (cp = (char_u *)alloc(lengte + 1))
+	if (cp = alloc(lengte + 1))
 	    strcpy((char *)cp, buffer);
 	return(cp);
     }
     else if ((sbuf = getenv((char *)lognam)))
     {
 	lengte = strlen(sbuf) + 1;
-	cp = (char_u *)alloc(lengte);
+	cp = alloc(lengte);
 	if (cp)
 	    strcpy((char *)cp, sbuf);
 	return cp;
@@ -382,7 +382,7 @@ vms_wproc(char *name, int val)
     if (vms_match_num == 0) {
 	/* first time through, setup some things */
 	if (NULL == vms_fmatch) {
-	    vms_fmatch = (char_u **)alloc(EXPL_ALLOC_INC * sizeof(char *));
+	    vms_fmatch = ALLOC_MULT(char *, EXPL_ALLOC_INC);
 	    if (!vms_fmatch)
 		return 0;
 	    vms_match_alloced = EXPL_ALLOC_INC;
@@ -406,7 +406,7 @@ vms_wproc(char *name, int val)
     if (--vms_match_free == 0) {
 	/* add more space to store matches */
 	vms_match_alloced += EXPL_ALLOC_INC;
-	vms_fmatch = (char_u **)vim_realloc(vms_fmatch,
+	vms_fmatch = vim_realloc(vms_fmatch,
 		sizeof(char **) * vms_match_alloced);
 	if (!vms_fmatch)
 	    return 0;
@@ -443,7 +443,7 @@ mch_expand_wildcards(int num_pat, char_u
     *num_file = 0;			/* default: no files found	*/
     files_alloced = EXPL_ALLOC_INC;
     files_free = EXPL_ALLOC_INC;
-    *file = (char_u **) alloc(sizeof(char_u **) * files_alloced);
+    *file = ALLOC_MULT(char_u **, files_alloced);
     if (*file == NULL)
     {
 	*num_file = 0;
@@ -490,8 +490,7 @@ mch_expand_wildcards(int num_pat, char_u
 	    if (--files_free < 1)
 	    {
 		files_alloced += EXPL_ALLOC_INC;
-		*file = (char_u **)vim_realloc(*file,
-		    sizeof(char_u **) * files_alloced);
+		*file = vim_realloc(*file, sizeof(char_u **) * files_alloced);
 		if (*file == NULL)
 		{
 		    *file = (char_u **)"";
@@ -649,15 +648,12 @@ vms_fixfilename(void *instring)
     if (len > buflen)
     {
 	buflen = len + 128;
-	if (buf)
-	    buf = (char *)vim_realloc(buf, buflen);
-	else
-	    buf = (char *)alloc(buflen * sizeof(char));
+	buf = vim_realloc(buf, buflen * sizeof(char));
     }
 
 #ifdef DEBUG
      char		 *tmpbuf = NULL;
-     tmpbuf = (char *)alloc(buflen * sizeof(char));
+     tmpbuf = ALLOC_MULT(char, buflen);
      strcpy(tmpbuf, instring);
 #endif
 
--- a/src/os_win32.c
+++ b/src/os_win32.c
@@ -2075,7 +2075,7 @@ executable_exists(char *name, char_u **p
 	return FALSE;
 
     wcurpath = _wgetenv(L"PATH");
-    wnewpath = (WCHAR *)alloc((wcslen(wcurpath) + 3) * sizeof(WCHAR));
+    wnewpath = ALLOC_MULT(WCHAR, wcslen(wcurpath) + 3);
     if (wnewpath == NULL)
 	return FALSE;
     wcscpy(wnewpath, L".;");
@@ -2338,7 +2338,7 @@ SaveConsoleBuffer(
 	cb->BufferSize.Y = cb->Info.dwSize.Y;
 	NumCells = cb->BufferSize.X * cb->BufferSize.Y;
 	vim_free(cb->Buffer);
-	cb->Buffer = (PCHAR_INFO)alloc(NumCells * sizeof(CHAR_INFO));
+	cb->Buffer = ALLOC_MULT(CHAR_INFO, NumCells);
 	if (cb->Buffer == NULL)
 	    return FALSE;
     }
@@ -2362,7 +2362,7 @@ SaveConsoleBuffer(
     {
 	cb->NumRegions = numregions;
 	vim_free(cb->Regions);
-	cb->Regions = (PSMALL_RECT)alloc(cb->NumRegions * sizeof(SMALL_RECT));
+	cb->Regions = ALLOC_MULT(SMALL_RECT, cb->NumRegions);
 	if (cb->Regions == NULL)
 	{
 	    VIM_CLEAR(cb->Buffer);
@@ -3394,7 +3394,7 @@ mch_get_acl(char_u *fname)
     struct my_acl   *p = NULL;
     DWORD   err;
 
-    p = (struct my_acl *)alloc_clear(sizeof(struct my_acl));
+    p = ALLOC_CLEAR_ONE(struct my_acl);
     if (p != NULL)
     {
 	WCHAR	*wn;
@@ -5952,7 +5952,7 @@ visual_bell(void)
     WORD    attrFlash = ~g_attrCurrent & 0xff;
 
     DWORD   dwDummy;
-    LPWORD  oldattrs = (LPWORD)alloc(Rows * Columns * sizeof(WORD));
+    LPWORD  oldattrs = ALLOC_MULT(WORD, Rows * Columns);
 
     if (oldattrs == NULL)
 	return;
@@ -6003,7 +6003,7 @@ write_chars(
     if (unicodebuf == NULL || length > unibuflen)
     {
 	vim_free(unicodebuf);
-	unicodebuf = (WCHAR *)lalloc(length * sizeof(WCHAR), FALSE);
+	unicodebuf = LALLOC_MULT(WCHAR, length);
 	unibuflen = length;
     }
     MultiByteToWideChar(cp, 0, (LPCSTR)pchBuf, cbToWrite,
@@ -7117,7 +7117,7 @@ fix_arg_enc(void)
 	return;
 
     /* Remember the buffer numbers for the arguments. */
-    fnum_list = (int *)alloc(sizeof(int) * GARGCOUNT);
+    fnum_list = ALLOC_MULT(int, GARGCOUNT);
     if (fnum_list == NULL)
 	return;		/* out of memory */
     for (i = 0; i < GARGCOUNT; ++i)
--- a/src/popupmnu.c
+++ b/src/popupmnu.c
@@ -1071,7 +1071,7 @@ split_message(char_u *mesg, pumitem_T **
      * position. */
     if (height > max_height)
 	height = max_height;
-    *array = (pumitem_T *)alloc_clear(sizeof(pumitem_T) * height);
+    *array = ALLOC_CLEAR_MULT(pumitem_T, height);
     if (*array == NULL)
 	goto failed;
 
@@ -1164,8 +1164,7 @@ ui_post_balloon(char_u *mesg, list_T *li
 	int	    idx;
 
 	balloon_arraysize = list->lv_len;
-	balloon_array = (pumitem_T *)alloc_clear(
-					     sizeof(pumitem_T) * list->lv_len);
+	balloon_array = ALLOC_CLEAR_MULT(pumitem_T, list->lv_len);
 	if (balloon_array == NULL)
 	    return;
 	for (idx = 0, li = list->lv_first; li != NULL; li = li->li_next, ++idx)
@@ -1271,7 +1270,7 @@ pum_show_popupmenu(vimmenu_T *menu)
 	return;
     }
 
-    array = (pumitem_T *)alloc_clear(sizeof(pumitem_T) * pum_size);
+    array = ALLOC_CLEAR_MULT(pumitem_T, pum_size);
     if (array == NULL)
 	return;
 
--- a/src/proto/misc2.pro
+++ b/src/proto/misc2.pro
@@ -21,13 +21,13 @@ void adjust_cursor_col(void);
 int leftcol_changed(void);
 void vim_mem_profile_dump(void);
 int alloc_does_fail(size_t size);
-char_u *alloc(size_t size);
-char_u *alloc_id(size_t size, alloc_id_T id);
-char_u *alloc_clear(size_t size);
-char_u *alloc_clear_id(size_t size, alloc_id_T id);
-char_u *lalloc_clear(size_t size, int message);
-char_u *lalloc(size_t size, int message);
-char_u *lalloc_id(size_t size, int message, alloc_id_T id);
+void *alloc(size_t size);
+void *alloc_id(size_t size, alloc_id_T id);
+void *alloc_clear(size_t size);
+void *alloc_clear_id(size_t size, alloc_id_T id);
+void *lalloc_clear(size_t size, int message);
+void *lalloc(size_t size, int message);
+void *lalloc_id(size_t size, int message, alloc_id_T id);
 void *mem_realloc(void *ptr, size_t size);
 void do_outofmem_msg(size_t size);
 void free_all_mem(void);
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -540,7 +540,7 @@ parse_efm_option(char_u *efm)
     while (efm[0] != NUL)
     {
 	// Allocate a new eformat structure and put it at the end of the list
-	fmt_ptr = (efm_T *)alloc_clear(sizeof(efm_T));
+	fmt_ptr = ALLOC_CLEAR_ONE(efm_T);
 	if (fmt_ptr == NULL)
 	    goto parse_efm_error;
 	if (fmt_first == NULL)	    // first one
@@ -1890,7 +1890,7 @@ locstack_queue_delreq(qf_info_T *qi)
 {
     qf_delq_T	*q;
 
-    q = (qf_delq_T *)alloc(sizeof(qf_delq_T));
+    q = ALLOC_ONE(qf_delq_T);
     if (q != NULL)
     {
 	q->qi = qi;
@@ -2063,7 +2063,7 @@ qf_add_entry(
     qfline_T	*qfp;
     qfline_T	**lastp;	// pointer to qf_last or NULL
 
-    if ((qfp = (qfline_T *)alloc(sizeof(qfline_T))) == NULL)
+    if ((qfp = ALLOC_ONE(qfline_T)) == NULL)
 	return QF_FAIL;
     if (bufnum != 0)
     {
@@ -2141,7 +2141,7 @@ qf_alloc_stack(qfltype_T qfltype)
 {
     qf_info_T *qi;
 
-    qi = (qf_info_T *)alloc_clear(sizeof(qf_info_T));
+    qi = ALLOC_CLEAR_ONE(qf_info_T);
     if (qi != NULL)
     {
 	qi->qf_refcount++;
@@ -2429,7 +2429,7 @@ qf_push_dir(char_u *dirbuf, struct dir_s
     struct dir_stack_T  *ds_ptr;
 
     // allocate new stack element and hook it in
-    ds_new = (struct dir_stack_T *)alloc(sizeof(struct dir_stack_T));
+    ds_new = ALLOC_ONE(struct dir_stack_T);
     if (ds_new == NULL)
 	return NULL;
 
--- a/src/regexp.c
+++ b/src/regexp.c
@@ -1319,7 +1319,7 @@ bt_regcomp(char_u *expr, int re_flags)
 	return NULL;
 
     /* Allocate space. */
-    r = (bt_regprog_T *)alloc(sizeof(bt_regprog_T) + regsize);
+    r = alloc(sizeof(bt_regprog_T) + regsize);
     if (r == NULL)
 	return NULL;
     r->re_in_use = FALSE;
@@ -3932,7 +3932,7 @@ make_extmatch(void)
 {
     reg_extmatch_T	*em;
 
-    em = (reg_extmatch_T *)alloc_clear(sizeof(reg_extmatch_T));
+    em = ALLOC_CLEAR_ONE(reg_extmatch_T);
     if (em != NULL)
 	em->refcnt = 1;
     return em;
--- a/src/regexp_nfa.c
+++ b/src/regexp_nfa.c
@@ -300,7 +300,7 @@ nfa_regcomp_start(
     /* Size for postfix representation of expr. */
     postfix_size = sizeof(int) * nstate_max;
 
-    post_start = (int *)alloc(postfix_size);
+    post_start = alloc(postfix_size);
     if (post_start == NULL)
 	return FAIL;
     post_ptr = post_start;
@@ -516,7 +516,7 @@ realloc_post_list(void)
     // For weird patterns the number of states can be very high. Increasing by
     // 50% seems a reasonable compromise between memory use and speed.
     new_max = nstate_max * 3 / 2;
-    new_start = (int *)alloc(new_max * sizeof(int));
+    new_start = ALLOC_MULT(int, new_max);
     if (new_start == NULL)
 	return FAIL;
     mch_memmove(new_start, post_start, nstate_max * sizeof(int));
@@ -3214,7 +3214,7 @@ post2nfa(int *postfix, int *end, int nfa
     if (nfa_calc_size == FALSE)
     {
 	// Allocate space for the stack. Max states on the stack: "nstate'.
-	stack = (Frag_T *)alloc((nstate + 1) * sizeof(Frag_T));
+	stack = ALLOC_MULT(Frag_T, nstate + 1);
 	if (stack == NULL)
 	    return NULL;
 	stackp = stack;
@@ -4799,7 +4799,7 @@ addstate_here(
 		emsg(_(e_maxmempat));
 		return NULL;
 	    }
-	    newl = (nfa_thread_T *)alloc(newsize);
+	    newl = alloc(newsize);
 	    if (newl == NULL)
 		return NULL;
 	    l->len = newlen;
@@ -5184,7 +5184,7 @@ recursive_regmatch(
 	if (*listids == NULL || *listids_len < prog->nstate)
 	{
 	    vim_free(*listids);
-	    *listids = (int *)alloc(sizeof(int) * prog->nstate);
+	    *listids = ALLOC_MULT(int, prog->nstate);
 	    if (*listids == NULL)
 	    {
 		emsg(_("E878: (NFA) Could not allocate memory for branch traversal!"));
@@ -5567,9 +5567,9 @@ nfa_regmatch(
     /* Allocate memory for the lists of nodes. */
     size = (prog->nstate + 1) * sizeof(nfa_thread_T);
 
-    list[0].t = (nfa_thread_T *)alloc(size);
+    list[0].t = alloc(size);
     list[0].len = prog->nstate + 1;
-    list[1].t = (nfa_thread_T *)alloc(size);
+    list[1].t = alloc(size);
     list[1].len = prog->nstate + 1;
     if (list[0].t == NULL || list[1].t == NULL)
 	goto theend;
@@ -7276,7 +7276,7 @@ nfa_regcomp(char_u *expr, int re_flags)
 
     /* allocate the regprog with space for the compiled regexp */
     prog_size = sizeof(nfa_regprog_T) + sizeof(nfa_state_T) * (nstate - 1);
-    prog = (nfa_regprog_T *)alloc(prog_size);
+    prog = alloc(prog_size);
     if (prog == NULL)
 	goto fail;
     state_ptr = prog->state;
--- a/src/screen.c
+++ b/src/screen.c
@@ -328,27 +328,25 @@ redraw_asap(int type)
 
     /* Allocate space to save the text displayed in the command line area. */
     rows = screen_Rows - cmdline_row;
-    screenline = (schar_T *)lalloc(rows * cols * sizeof(schar_T), FALSE);
-    screenattr = (sattr_T *)lalloc(rows * cols * sizeof(sattr_T), FALSE);
+    screenline = LALLOC_MULT(schar_T, rows * cols);
+    screenattr = LALLOC_MULT(sattr_T, rows * cols);
     if (screenline == NULL || screenattr == NULL)
 	ret = 2;
     if (enc_utf8)
     {
-	screenlineUC = (u8char_T *)lalloc(
-				       rows * cols * sizeof(u8char_T), FALSE);
+	screenlineUC = LALLOC_MULT(u8char_T, rows * cols);
 	if (screenlineUC == NULL)
 	    ret = 2;
 	for (i = 0; i < p_mco; ++i)
 	{
-	    screenlineC[i] = (u8char_T *)lalloc(
-				       rows * cols * sizeof(u8char_T), FALSE);
+	    screenlineC[i] = LALLOC_MULT(u8char_T, rows * cols);
 	    if (screenlineC[i] == NULL)
 		ret = 2;
 	}
     }
     if (enc_dbcs == DBCS_JPNU)
     {
-	screenline2 = (schar_T *)lalloc(rows * cols * sizeof(schar_T), FALSE);
+	screenline2 = LALLOC_MULT(schar_T, rows * cols);
 	if (screenline2 == NULL)
 	    ret = 2;
     }
@@ -3810,14 +3808,13 @@ win_line(
 	{
 	    // Make a copy of the properties, so that they are properly
 	    // aligned.
-	    text_props = (textprop_T *)alloc(
-					 text_prop_count * sizeof(textprop_T));
+	    text_props = ALLOC_MULT(textprop_T, text_prop_count);
 	    if (text_props != NULL)
 		mch_memmove(text_props, prop_start,
 					 text_prop_count * sizeof(textprop_T));
 
 	    // Allocate an array for the indexes.
-	    text_prop_idxs = (int *)alloc(text_prop_count * sizeof(int));
+	    text_prop_idxs = ALLOC_MULT(int, text_prop_count);
 	    area_highlighting = TRUE;
 	    extra_check = TRUE;
 	}
@@ -8901,25 +8898,21 @@ retry:
     if (aucmd_win != NULL)
 	win_free_lsize(aucmd_win);
 
-    new_ScreenLines = (schar_T *)lalloc(
-			      (Rows + 1) * Columns * sizeof(schar_T), FALSE);
+    new_ScreenLines = LALLOC_MULT(schar_T, (Rows + 1) * Columns);
     vim_memset(new_ScreenLinesC, 0, sizeof(u8char_T *) * MAX_MCO);
     if (enc_utf8)
     {
-	new_ScreenLinesUC = (u8char_T *)lalloc(
-			     (Rows + 1) * Columns * sizeof(u8char_T), FALSE);
+	new_ScreenLinesUC = LALLOC_MULT(u8char_T, (Rows + 1) * Columns);
 	for (i = 0; i < p_mco; ++i)
-	    new_ScreenLinesC[i] = (u8char_T *)lalloc_clear(
-			     (Rows + 1) * Columns * sizeof(u8char_T), FALSE);
+	    new_ScreenLinesC[i] = LALLOC_CLEAR_MULT(u8char_T,
+							 (Rows + 1) * Columns);
     }
     if (enc_dbcs == DBCS_JPNU)
-	new_ScreenLines2 = (schar_T *)lalloc(
-			     (Rows + 1) * Columns * sizeof(schar_T), FALSE);
-    new_ScreenAttrs = (sattr_T *)lalloc(
-			      (Rows + 1) * Columns * sizeof(sattr_T), FALSE);
-    new_LineOffset = (unsigned *)lalloc(Rows * sizeof(unsigned), FALSE);
-    new_LineWraps = (char_u *)lalloc(Rows * sizeof(char_u), FALSE);
-    new_TabPageIdxs = (short *)lalloc(Columns * sizeof(short), FALSE);
+	new_ScreenLines2 = LALLOC_MULT(schar_T, (Rows + 1) * Columns);
+    new_ScreenAttrs = LALLOC_MULT(sattr_T, (Rows + 1) * Columns);
+    new_LineOffset = LALLOC_MULT(unsigned, Rows);
+    new_LineWraps = LALLOC_MULT(char_u, Rows);
+    new_TabPageIdxs = LALLOC_MULT(short, Columns);
 
     FOR_ALL_TAB_WINDOWS(tp, wp)
     {
@@ -10858,8 +10851,7 @@ redraw_win_toolbar(win_T *wp)
     vim_free(wp->w_winbar_items);
     for (menu = wp->w_winbar->children; menu != NULL; menu = menu->next)
 	++item_count;
-    wp->w_winbar_items = (winbar_item_T *)alloc_clear(
-				     sizeof(winbar_item_T) * (item_count + 1));
+    wp->w_winbar_items = ALLOC_CLEAR_MULT(winbar_item_T, item_count + 1);
 
     /* TODO: use fewer spaces if there is not enough room */
     for (menu = wp->w_winbar->children;
--- a/src/search.c
+++ b/src/search.c
@@ -5145,8 +5145,7 @@ find_pattern_in_path(
 	    goto fpip_end;
 	def_regmatch.rm_ic = FALSE;	/* don't ignore case in define pat. */
     }
-    files = (SearchedFile *)lalloc_clear(
-				  max_path_depth * sizeof(SearchedFile), TRUE);
+    files = lalloc_clear(max_path_depth * sizeof(SearchedFile), TRUE);
     if (files == NULL)
 	goto fpip_end;
     old_files = max_path_depth;
@@ -5306,8 +5305,7 @@ find_pattern_in_path(
 		/* Push the new file onto the file stack */
 		if (depth + 1 == old_files)
 		{
-		    bigger = (SearchedFile *)alloc(
-				    max_path_depth * 2 * sizeof(SearchedFile));
+		    bigger = ALLOC_MULT(SearchedFile, max_path_depth * 2);
 		    if (bigger != NULL)
 		    {
 			for (i = 0; i <= depth; i++)
--- a/src/sign.c
+++ b/src/sign.c
@@ -85,7 +85,7 @@ sign_group_ref(char_u *groupname)
     if (HASHITEM_EMPTY(hi))
     {
 	// new group
-	group = (signgroup_T *)alloc(sizeof(signgroup_T) + STRLEN(groupname));
+	group = alloc(sizeof(signgroup_T) + STRLEN(groupname));
 	if (group == NULL)
 	    return NULL;
 	STRCPY(group->sg_name, groupname);
@@ -201,8 +201,7 @@ insert_sign(
 {
     signlist_T	*newsign;
 
-    newsign = (signlist_T *)lalloc_id(sizeof(signlist_T), FALSE,
-							      aid_insert_sign);
+    newsign = lalloc_id(sizeof(signlist_T), FALSE, aid_insert_sign);
     if (newsign != NULL)
     {
 	newsign->id = id;
@@ -736,7 +735,7 @@ alloc_new_sign(char_u *name)
     int	start = next_sign_typenr;
 
     // Allocate a new sign.
-    sp = (sign_T *)alloc_clear_id(sizeof(sign_T), aid_sign_define_by_name);
+    sp = alloc_clear_id(sizeof(sign_T), aid_sign_define_by_name);
     if (sp == NULL)
 	return NULL;
 
--- a/src/spell.c
+++ b/src/spell.c
@@ -1899,7 +1899,7 @@ slang_alloc(char_u *lang)
 {
     slang_T *lp;
 
-    lp = (slang_T *)alloc_clear(sizeof(slang_T));
+    lp = ALLOC_CLEAR_ONE(slang_T);
     if (lp != NULL)
     {
 	if (lang != NULL)
@@ -2083,7 +2083,7 @@ count_common_word(
     hi = hash_lookup(&lp->sl_wordcount, p, hash);
     if (HASHITEM_EMPTY(hi))
     {
-	wc = (wordcount_T *)alloc(sizeof(wordcount_T) + STRLEN(p));
+	wc = alloc(sizeof(wordcount_T) + STRLEN(p));
 	if (wc == NULL)
 	    return;
 	STRCPY(wc->wc_word, p);
@@ -2883,7 +2883,7 @@ open_spellbuf(void)
 {
     buf_T	*buf;
 
-    buf = (buf_T *)alloc_clear(sizeof(buf_T));
+    buf = ALLOC_CLEAR_ONE(buf_T);
     if (buf != NULL)
     {
 	buf->b_spell = TRUE;
@@ -6223,7 +6223,7 @@ add_sound_suggest(
     hi = hash_lookup(&slang->sl_sounddone, goodword, hash);
     if (HASHITEM_EMPTY(hi))
     {
-	sft = (sftword_T *)alloc(sizeof(sftword_T) + STRLEN(goodword));
+	sft = alloc(sizeof(sftword_T) + STRLEN(goodword));
 	if (sft != NULL)
 	{
 	    sft->sft_score = score;
@@ -7820,7 +7820,7 @@ spell_edit_score(
 
     /* We use "cnt" as an array: CNT(badword_idx, goodword_idx). */
 #define CNT(a, b)   cnt[(a) + (b) * (badlen + 1)]
-    cnt = (int *)alloc(sizeof(int) * (badlen + 1) * (goodlen + 1));
+    cnt = ALLOC_MULT(int, (badlen + 1) * (goodlen + 1));
     if (cnt == NULL)
 	return 0;	/* out of memory */
 
--- a/src/spellfile.c
+++ b/src/spellfile.c
@@ -892,7 +892,7 @@ read_prefcond_section(FILE *fd, slang_T 
     if (cnt <= 0)
 	return SP_FORMERROR;
 
-    lp->sl_prefprog = (regprog_T **)alloc_clear(sizeof(regprog_T *) * cnt);
+    lp->sl_prefprog = ALLOC_CLEAR_MULT(regprog_T *, cnt);
     if (lp->sl_prefprog == NULL)
 	return SP_OTHERERROR;
     lp->sl_prefixcnt = cnt;
@@ -1539,7 +1539,7 @@ mb_str2wide(char_u *s)
     char_u	*p;
     int		i = 0;
 
-    res = (int *)alloc(sizeof(int) * (mb_charlen(s) + 1));
+    res = ALLOC_MULT(int, mb_charlen(s) + 1);
     if (res != NULL)
     {
 	for (p = s; *p != NUL; )
@@ -1585,7 +1585,7 @@ spell_read_tree(
 	*bytsp = bp;
 
 	/* Allocate the index array. */
-	ip = (idx_T *)lalloc_clear(len * sizeof(int), TRUE);
+	ip = lalloc_clear(len * sizeof(int), TRUE);
 	if (ip == NULL)
 	    return SP_OTHERERROR;
 	*idxsp = ip;
@@ -4271,7 +4271,7 @@ getroom(
 	    bl = NULL;
 	else
 	    /* Allocate a block of memory. It is not freed until much later. */
-	    bl = (sblock_T *)alloc_clear(sizeof(sblock_T) + SBLOCKSIZE);
+	    bl = alloc_clear(sizeof(sblock_T) + SBLOCKSIZE);
 	if (bl == NULL)
 	{
 	    if (!spin->si_did_emsg)
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -1215,7 +1215,7 @@ syn_stack_alloc(void)
 		len = syn_block->b_sst_len - syn_block->b_sst_freecount + 2;
 	}
 
-	sstp = (synstate_T *)alloc_clear(len * sizeof(synstate_T));
+	sstp = ALLOC_CLEAR_MULT(synstate_T, len);
 	if (sstp == NULL)	/* out of memory! */
 	    return;
 
@@ -4494,7 +4494,7 @@ add_keyword(
 						 name_folded, MAXKEYWLEN + 1);
     else
 	name_ic = name;
-    kp = (keyentry_T *)alloc(sizeof(keyentry_T) + STRLEN(name_ic));
+    kp = alloc(sizeof(keyentry_T) + STRLEN(name_ic));
     if (kp == NULL)
 	return;
     STRCPY(kp->keyword, name_ic);
@@ -4757,15 +4757,15 @@ syn_incl_toplevel(int id, int *flagsp)
     if (curwin->w_s->b_syn_topgrp >= SYNID_CLUSTER)
     {
 	/* We have to alloc this, because syn_combine_list() will free it. */
-	short	    *grp_list = (short *)alloc(2 * sizeof(short));
+	short	    *grp_list = ALLOC_MULT(short, 2);
 	int	    tlg_id = curwin->w_s->b_syn_topgrp - SYNID_CLUSTER;
 
 	if (grp_list != NULL)
 	{
 	    grp_list[0] = id;
 	    grp_list[1] = 0;
-	    syn_combine_list(&SYN_CLSTR(curwin->w_s)[tlg_id].scl_list, &grp_list,
-			 CLUSTER_ADD);
+	    syn_combine_list(&SYN_CLSTR(curwin->w_s)[tlg_id].scl_list,
+						       &grp_list, CLUSTER_ADD);
 	}
     }
 }
@@ -5208,7 +5208,7 @@ syn_cmd_region(
 	     * syn_patterns for this item, at the start (because the list is
 	     * used from end to start).
 	     */
-	    ppp = (struct pat_ptr *)alloc(sizeof(struct pat_ptr));
+	    ppp = ALLOC_ONE(struct pat_ptr);
 	    if (ppp == NULL)
 	    {
 		rest = NULL;
@@ -5216,7 +5216,7 @@ syn_cmd_region(
 	    }
 	    ppp->pp_next = pat_ptrs[item];
 	    pat_ptrs[item] = ppp;
-	    ppp->pp_synp = (synpat_T *)alloc_clear(sizeof(synpat_T));
+	    ppp->pp_synp = ALLOC_CLEAR_ONE(synpat_T);
 	    if (ppp->pp_synp == NULL)
 	    {
 		rest = NULL;
@@ -5465,7 +5465,7 @@ syn_combine_list(short **clstr1, short *
 		clstr = NULL;
 		break;
 	    }
-	    clstr = (short *)alloc((count + 1) * sizeof(short));
+	    clstr = ALLOC_MULT(short, count + 1);
 	    if (clstr == NULL)
 		break;
 	    clstr[count] = 0;
@@ -6124,7 +6124,7 @@ get_id_list(
 	    break;
 	if (round == 1)
 	{
-	    retval = (short *)alloc((count + 1) * sizeof(short));
+	    retval = ALLOC_MULT(short, count + 1);
 	    if (retval == NULL)
 		break;
 	    retval[count] = 0;	    /* zero means end of the list */
@@ -6163,7 +6163,7 @@ copy_id_list(short *list)
     for (count = 0; list[count]; ++count)
 	;
     len = (count + 1) * sizeof(short);
-    retval = (short *)alloc(len);
+    retval = alloc(len);
     if (retval != NULL)
 	mch_memmove(retval, list, (size_t)len);
 
@@ -6355,7 +6355,7 @@ ex_ownsyntax(exarg_T *eap)
 
     if (curwin->w_s == &curwin->w_buffer->b_s)
     {
-	curwin->w_s = (synblock_T *)alloc(sizeof(synblock_T));
+	curwin->w_s = ALLOC_ONE(synblock_T);
 	memset(curwin->w_s, 0, sizeof(synblock_T));
 	hash_init(&curwin->w_s->b_keywtab);
 	hash_init(&curwin->w_s->b_keywtab_ic);
--- a/src/tag.c
+++ b/src/tag.c
@@ -1430,7 +1430,7 @@ find_tagfunc_tags(
 	if (name_only)
 	    mfp = vim_strsave(res_name);
 	else
-	    mfp = (char_u *)alloc(sizeof(char_u) + len + 1);
+	    mfp = alloc(sizeof(char_u) + len + 1);
 
 	if (mfp == NULL)
 	    continue;
@@ -2536,8 +2536,7 @@ parse_line:
 		     */
 		    *tagp.tagname_end = NUL;
 		    len = (int)(tagp.tagname_end - tagp.tagname);
-		    mfp = (char_u *)alloc(sizeof(char_u)
-						    + len + 10 + ML_EXTRA + 1);
+		    mfp = alloc(sizeof(char_u) + len + 10 + ML_EXTRA + 1);
 		    if (mfp != NULL)
 		    {
 			int heuristic;
@@ -2574,7 +2573,7 @@ parse_line:
 			if (tagp.command + 2 < temp_end)
 			{
 			    len = (int)(temp_end - tagp.command - 2);
-			    mfp = (char_u *)alloc(len + 2);
+			    mfp = alloc(len + 2);
 			    if (mfp != NULL)
 				vim_strncpy(mfp, tagp.command + 2, len);
 			}
@@ -2585,7 +2584,7 @@ parse_line:
 		    else
 		    {
 			len = (int)(tagp.tagname_end - tagp.tagname);
-			mfp = (char_u *)alloc(sizeof(char_u) + len + 1);
+			mfp = alloc(sizeof(char_u) + len + 1);
 			if (mfp != NULL)
 			    vim_strncpy(mfp, tagp.tagname, len);
 
@@ -2620,7 +2619,7 @@ parse_line:
 		    else
 			++len;
 #endif
-		    mfp = (char_u *)alloc(sizeof(char_u) + len + 1);
+		    mfp = alloc(sizeof(char_u) + len + 1);
 		    if (mfp != NULL)
 		    {
 			p = mfp;
@@ -2789,7 +2788,7 @@ findtag_end:
 	match_count = 0;
 
     if (match_count > 0)
-	matches = (char_u **)alloc(match_count * sizeof(char_u *));
+	matches = ALLOC_MULT(char_u *, match_count);
     else
 	matches = NULL;
     match_count = 0;
--- a/src/term.c
+++ b/src/term.c
@@ -4187,8 +4187,7 @@ add_termcode(char_u *name, char_u *strin
     if (tc_len == tc_max_len)
     {
 	tc_max_len += 20;
-	new_tc = (struct termcode *)alloc(
-			    tc_max_len * sizeof(struct termcode));
+	new_tc = ALLOC_MULT(struct termcode, tc_max_len);
 	if (new_tc == NULL)
 	{
 	    tc_max_len -= 20;
@@ -6420,7 +6419,7 @@ show_termcodes(void)
 
     if (tc_len == 0)	    /* no terminal codes (must be GUI) */
 	return;
-    items = (int *)alloc(sizeof(int) * tc_len);
+    items = ALLOC_MULT(int, tc_len);
     if (items == NULL)
 	return;
 
@@ -7071,8 +7070,7 @@ gui_get_color_cmn(char_u *name)
 	{
 	    if (!counting)
 	    {
-		colornames_table = (struct rgbcolor_table_S *)alloc(
-				    sizeof(struct rgbcolor_table_S) * size);
+		colornames_table = ALLOC_MULT(struct rgbcolor_table_S, size);
 		if (colornames_table == NULL)
 		{
 		    fclose(fd);
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -413,7 +413,7 @@ term_start(
 	return NULL;
     }
 
-    term = (term_T *)alloc_clear(sizeof(term_T));
+    term = ALLOC_CLEAR_ONE(term_T);
     if (term == NULL)
 	return NULL;
     term->tl_dirty_row_end = MAX_ROW;
@@ -1630,7 +1630,7 @@ update_snapshot(term_T *term)
 	    if (len == 0)
 		p = NULL;
 	    else
-		p = (cellattr_T *)alloc(sizeof(cellattr_T) * len);
+		p = ALLOC_MULT(cellattr_T, len);
 	    if ((p != NULL || len == 0)
 				     && ga_grow(&term->tl_scrollback, 1) == OK)
 	    {
@@ -2884,7 +2884,7 @@ handle_pushline(int cols, const VTermScr
 
 	ga_init2(&ga, 1, 100);
 	if (len > 0)
-	    p = (cellattr_T *)alloc(sizeof(cellattr_T) * len);
+	    p = ALLOC_MULT(cellattr_T, len);
 	if (p != NULL)
 	{
 	    for (col = 0; col < len; col += cells[col].width)
@@ -4935,7 +4935,7 @@ term_swap_diff()
     else
     {
 	size_t		size = sizeof(sb_line_T) * term->tl_scrollback.ga_len;
-	sb_line_T	*temp = (sb_line_T *)alloc(size);
+	sb_line_T	*temp = alloc(size);
 
 	/* need to copy cell properties into temp memory */
 	if (temp != NULL)
@@ -5800,7 +5800,7 @@ conpty_term_and_job_init(
     {
 	/* Request by CreateProcessW */
 	breq = wcslen(cmd_wchar) + 1 + 1;	/* Addition of NUL by API */
-	cmd_wchar_copy = (PWSTR)alloc(breq * sizeof(WCHAR));
+	cmd_wchar_copy = ALLOC_MULT(WCHAR, breq);
 	wcsncpy(cmd_wchar_copy, cmd_wchar, breq - 1);
     }
 
@@ -5829,8 +5829,7 @@ conpty_term_and_job_init(
 
     /* Set up pipe inheritance safely: Vista or later. */
     pInitializeProcThreadAttributeList(NULL, 1, 0, &breq);
-    term->tl_siex.lpAttributeList =
-	    (PPROC_THREAD_ATTRIBUTE_LIST)alloc(breq);
+    term->tl_siex.lpAttributeList = alloc(breq);
     if (!term->tl_siex.lpAttributeList)
 	goto failed;
     if (!pInitializeProcThreadAttributeList(term->tl_siex.lpAttributeList, 1,
--- a/src/testdir/test_cscope.vim
+++ b/src/testdir/test_cscope.vim
@@ -123,8 +123,8 @@ func Test_cscopeWithCscopeConnections()
     if cs_version >= 15.8
       for cmd in ['cs find a item', 'cs find 9 item']
         let a = execute(cmd)
-        call assert_equal(['', '(1 of 4): <<test_mf_hash>> item = (mf_hashitem_T *)lalloc_clear(sizeof(mf_hashtab_T), FALSE);'], split(a, '\n', 1))
-        call assert_equal('	item = (mf_hashitem_T *)lalloc_clear(sizeof(mf_hashtab_T), FALSE);', getline('.'))
+        call assert_equal(['', '(1 of 4): <<test_mf_hash>> item = LALLOC_CLEAR_ONE(mf_hashtab_T);'], split(a, '\n', 1))
+        call assert_equal('	item = LALLOC_CLEAR_ONE(mf_hashtab_T);', getline('.'))
         cnext
         call assert_equal('	item = mf_hash_find(&ht, key);', getline('.'))
         cnext
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -695,7 +695,7 @@ prop_type_set(typval_T *argvars, int add
 	    semsg(_("E969: Property type %s already defined"), name);
 	    return;
 	}
-	prop = (proptype_T *)alloc_clear(sizeof(proptype_T) + STRLEN(name));
+	prop = alloc_clear(sizeof(proptype_T) + STRLEN(name));
 	if (prop == NULL)
 	    return;
 	STRCPY(prop->pt_name, name);
@@ -703,7 +703,7 @@ prop_type_set(typval_T *argvars, int add
 	htp = buf == NULL ? &global_proptypes : &buf->b_proptypes;
 	if (*htp == NULL)
 	{
-	    *htp = (hashtab_T *)alloc(sizeof(hashtab_T));
+	    *htp = ALLOC_ONE(hashtab_T);
 	    if (*htp == NULL)
 	    {
 		vim_free(prop);
@@ -1177,7 +1177,7 @@ adjust_props_for_join(
     proplen = get_text_props(curbuf, lnum, &props, FALSE);
     if (proplen > 0)
     {
-	*prop_line = (textprop_T *)alloc(proplen * (int)sizeof(textprop_T));
+	*prop_line = ALLOC_MULT(textprop_T, proplen);
 	if (*prop_line != NULL)
 	{
 	    for (ri = 0; ri < proplen; ++ri)
--- a/src/ui.c
+++ b/src/ui.c
@@ -1897,7 +1897,7 @@ get_input_buf(void)
     garray_T	*gap;
 
     /* We use a growarray to store the data pointer and the length. */
-    gap = (garray_T *)alloc(sizeof(garray_T));
+    gap = ALLOC_ONE(garray_T);
     if (gap != NULL)
     {
 	/* Add one to avoid a zero size. */
--- a/src/undo.c
+++ b/src/undo.c
@@ -468,7 +468,7 @@ u_savecommon(
 	     * Make a new header entry.  Do this first so that we don't mess
 	     * up the undo info when out of memory.
 	     */
-	    uhp = (u_header_T *)U_ALLOC_LINE(sizeof(u_header_T));
+	    uhp = U_ALLOC_LINE(sizeof(u_header_T));
 	    if (uhp == NULL)
 		goto nomem;
 #ifdef U_DEBUG
@@ -659,7 +659,7 @@ u_savecommon(
     /*
      * add lines in front of entry list
      */
-    uep = (u_entry_T *)U_ALLOC_LINE(sizeof(u_entry_T));
+    uep = U_ALLOC_LINE(sizeof(u_entry_T));
     if (uep == NULL)
 	goto nomem;
     vim_memset(uep, 0, sizeof(u_entry_T));
@@ -685,8 +685,7 @@ u_savecommon(
 
     if (size > 0)
     {
-	if ((uep->ue_array = (undoline_T *)U_ALLOC_LINE(
-					   sizeof(undoline_T) * size)) == NULL)
+	if ((uep->ue_array = U_ALLOC_LINE(sizeof(undoline_T) * size)) == NULL)
 	{
 	    u_freeentry(uep, 0L);
 	    goto nomem;
@@ -1286,7 +1285,7 @@ unserialize_uhp(bufinfo_T *bi, char_u *f
     int		c;
     int		error;
 
-    uhp = (u_header_T *)U_ALLOC_LINE(sizeof(u_header_T));
+    uhp = U_ALLOC_LINE(sizeof(u_header_T));
     if (uhp == NULL)
 	return NULL;
     vim_memset(uhp, 0, sizeof(u_header_T));
@@ -1397,7 +1396,7 @@ unserialize_uep(bufinfo_T *bi, int *erro
     char_u	*line;
     int		line_len;
 
-    uep = (u_entry_T *)U_ALLOC_LINE(sizeof(u_entry_T));
+    uep = U_ALLOC_LINE(sizeof(u_entry_T));
     if (uep == NULL)
 	return NULL;
     vim_memset(uep, 0, sizeof(u_entry_T));
@@ -1411,7 +1410,7 @@ unserialize_uep(bufinfo_T *bi, int *erro
     if (uep->ue_size > 0)
     {
 	if (uep->ue_size < LONG_MAX / (int)sizeof(char_u *))
-	    array = (undoline_T *)U_ALLOC_LINE(sizeof(undoline_T) * uep->ue_size);
+	    array = U_ALLOC_LINE(sizeof(undoline_T) * uep->ue_size);
 	if (array == NULL)
 	{
 	    *error = TRUE;
@@ -1981,8 +1980,7 @@ u_read_undo(char_u *name, char_u *hash, 
     if (num_head > 0)
     {
 	if (num_head < LONG_MAX / (long)sizeof(u_header_T *))
-	    uhp_table = (u_header_T **)U_ALLOC_LINE(
-					     num_head * sizeof(u_header_T *));
+	    uhp_table = U_ALLOC_LINE(num_head * sizeof(u_header_T *));
 	if (uhp_table == NULL)
 	    goto error;
     }
@@ -2013,7 +2011,7 @@ u_read_undo(char_u *name, char_u *hash, 
     }
 
 #ifdef U_DEBUG
-    uhp_table_used = (int *)alloc_clear(sizeof(int) * num_head + 1);
+    uhp_table_used = alloc_clear(sizeof(int) * num_head + 1);
 # define SET_FLAG(j) ++uhp_table_used[j]
 #else
 # define SET_FLAG(j)
@@ -2712,8 +2710,7 @@ u_undoredo(int undo)
 	/* delete the lines between top and bot and save them in newarray */
 	if (oldsize > 0)
 	{
-	    if ((newarray = (undoline_T *)U_ALLOC_LINE(
-					sizeof(undoline_T) * oldsize)) == NULL)
+	    if ((newarray = U_ALLOC_LINE(sizeof(undoline_T) * oldsize)) == NULL)
 	    {
 		do_outofmem_msg((long_u)(sizeof(undoline_T) * oldsize));
 		/*
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -292,10 +292,10 @@ get_lambda_tv(char_u **arg, typval_T *re
 
 	sprintf((char*)name, "<lambda>%d", ++lambda_no);
 
-	fp = (ufunc_T *)alloc_clear(sizeof(ufunc_T) + STRLEN(name));
+	fp = alloc_clear(sizeof(ufunc_T) + STRLEN(name));
 	if (fp == NULL)
 	    goto errret;
-	pt = (partial_T *)alloc_clear(sizeof(partial_T));
+	pt = ALLOC_CLEAR_ONE(partial_T);
 	if (pt == NULL)
 	    goto errret;
 
@@ -305,7 +305,7 @@ get_lambda_tv(char_u **arg, typval_T *re
 
 	/* Add "return " before the expression. */
 	len = 7 + e - s + 1;
-	p = (char_u *)alloc(len);
+	p = alloc(len);
 	if (p == NULL)
 	    goto errret;
 	((char_u **)(newlines.ga_data))[newlines.ga_len++] = p;
@@ -802,7 +802,7 @@ call_user_func(
 
     line_breakcheck();		/* check for CTRL-C hit */
 
-    fc = (funccall_T *)alloc_clear(sizeof(funccall_T));
+    fc = ALLOC_CLEAR_ONE(funccall_T);
     if (fc == NULL)
 	return;
     fc->caller = current_funccal;
@@ -2580,7 +2580,7 @@ ex_function(exarg_T *eap)
 	    }
 	}
 
-	fp = (ufunc_T *)alloc_clear(sizeof(ufunc_T) + STRLEN(name));
+	fp = alloc_clear(sizeof(ufunc_T) + STRLEN(name));
 	if (fp == NULL)
 	    goto erret;
 
@@ -2751,13 +2751,11 @@ func_do_profile(ufunc_T *fp)
 	profile_zero(&fp->uf_tm_self);
 	profile_zero(&fp->uf_tm_total);
 	if (fp->uf_tml_count == NULL)
-	    fp->uf_tml_count = (int *)alloc_clear(sizeof(int) * len);
+	    fp->uf_tml_count = ALLOC_CLEAR_MULT(int, len);
 	if (fp->uf_tml_total == NULL)
-	    fp->uf_tml_total = (proftime_T *)alloc_clear(
-						     sizeof(proftime_T) * len);
+	    fp->uf_tml_total = ALLOC_CLEAR_MULT(proftime_T, len);
 	if (fp->uf_tml_self == NULL)
-	    fp->uf_tml_self = (proftime_T *)alloc_clear(
-						     sizeof(proftime_T) * len);
+	    fp->uf_tml_self = ALLOC_CLEAR_MULT(proftime_T, len);
 	fp->uf_tml_idx = -1;
 	if (fp->uf_tml_count == NULL || fp->uf_tml_total == NULL
 						    || fp->uf_tml_self == NULL)
@@ -2786,7 +2784,7 @@ func_dump_profile(FILE *fd)
     if (todo == 0)
 	return;     /* nothing to dump */
 
-    sorttab = (ufunc_T **)alloc(sizeof(ufunc_T *) * todo);
+    sorttab = ALLOC_MULT(ufunc_T *, todo);
 
     for (hi = func_hashtab.ht_array; todo > 0; ++hi)
     {
@@ -3670,7 +3668,7 @@ make_partial(dict_T *selfdict_in, typval
 
     if (fp != NULL && (fp->uf_flags & FC_DICT))
     {
-	partial_T	*pt = (partial_T *)alloc_clear(sizeof(partial_T));
+	partial_T	*pt = ALLOC_CLEAR_ONE(partial_T);
 
 	if (pt != NULL)
 	{
@@ -3704,8 +3702,7 @@ make_partial(dict_T *selfdict_in, typval
 		}
 		if (ret_pt->pt_argc > 0)
 		{
-		    pt->pt_argv = (typval_T *)alloc(
-				      sizeof(typval_T) * ret_pt->pt_argc);
+		    pt->pt_argv = ALLOC_MULT(typval_T, ret_pt->pt_argc);
 		    if (pt->pt_argv == NULL)
 			/* out of memory: drop the arguments */
 			pt->pt_argc = 0;
--- a/src/version.c
+++ b/src/version.c
@@ -61,7 +61,7 @@ init_longVersion(void)
 		+ strlen(VIM_VERSION_DATE_ONLY)
 		+ strlen(date_time);
 
-    longVersion = (char *)alloc(len);
+    longVersion = alloc(len);
     if (longVersion == NULL)
 	longVersion = VIM_VERSION_LONG;
     else
@@ -768,6 +768,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1414,
+/**/
     1413,
 /**/
     1412,
--- a/src/vim.h
+++ b/src/vim.h
@@ -1546,6 +1546,16 @@ typedef UINT32_TYPEDEF UINT32_T;
 # define R_OK 4		/* for systems that don't have R_OK in unistd.h */
 #endif
 
+// Allocate memory for one type and cast the returned pointer to have the
+// compiler check the types.
+#define ALLOC_ONE(type)  (type *)alloc(sizeof(type))
+#define ALLOC_MULT(type, count)  (type *)alloc(sizeof(type) * (count))
+#define ALLOC_CLEAR_ONE(type)  (type *)alloc_clear(sizeof(type))
+#define ALLOC_CLEAR_MULT(type, count)  (type *)alloc_clear(sizeof(type) * (count))
+#define LALLOC_CLEAR_ONE(type)  (type *)lalloc_clear(sizeof(type), FALSE)
+#define LALLOC_CLEAR_MULT(type, count)  (type *)lalloc_clear(sizeof(type) * (count), FALSE)
+#define LALLOC_MULT(type, count)  (type *)lalloc(sizeof(type) * (count), FALSE)
+
 /*
  * defines to avoid typecasts from (char_u *) to (char *) and back
  * (vim_strchr() and vim_strrchr() are now in alloc.c)
--- a/src/winclip.c
+++ b/src/winclip.c
@@ -149,7 +149,7 @@ MultiByteToWideChar_alloc(UINT cp, DWORD
 {
     *outlen = MultiByteToWideChar(cp, flags, in, inlen, 0, 0);
     /* Add one one word to avoid a zero-length alloc(). */
-    *out = (LPWSTR)alloc(sizeof(WCHAR) * (*outlen + 1));
+    *out = ALLOC_MULT(WCHAR, *outlen + 1);
     if (*out != NULL)
     {
 	MultiByteToWideChar(cp, flags, in, inlen, *out, *outlen);
@@ -169,7 +169,7 @@ WideCharToMultiByte_alloc(UINT cp, DWORD
 {
     *outlen = WideCharToMultiByte(cp, flags, in, inlen, NULL, 0, def, useddef);
     /* Add one one byte to avoid a zero-length alloc(). */
-    *out = (LPSTR)alloc(*outlen + 1);
+    *out = alloc(*outlen + 1);
     if (*out != NULL)
     {
 	WideCharToMultiByte(cp, flags, in, inlen, *out, *outlen, def, useddef);
@@ -512,7 +512,7 @@ clip_mch_set_selection(VimClipboard *cbd
 	    metadata.txtlen = WideCharToMultiByte(GetACP(), 0, out, len,
 							       NULL, 0, 0, 0);
 	    vim_free(str);
-	    str = (char_u *)alloc(metadata.txtlen == 0 ? 1 : metadata.txtlen);
+	    str = alloc(metadata.txtlen == 0 ? 1 : metadata.txtlen);
 	    if (str == NULL)
 	    {
 		vim_free(out);
@@ -654,7 +654,7 @@ enc_to_utf16(char_u *str, int *lenp)
 	convert_setup(&conv, NULL, NULL);
 
 	length = utf8_to_utf16(str, *lenp, NULL, NULL);
-	ret = (WCHAR *)alloc((length + 1) * sizeof(WCHAR));
+	ret = ALLOC_MULT(WCHAR, length + 1);
 	if (ret != NULL)
 	{
 	    utf8_to_utf16(str, *lenp, (short_u *)ret, NULL);
--- a/src/window.c
+++ b/src/window.c
@@ -1065,7 +1065,7 @@ win_split_ins(
     if (curfrp->fr_parent == NULL || curfrp->fr_parent->fr_layout != layout)
     {
 	/* Need to create a new frame in the tree to make a branch. */
-	frp = (frame_T *)alloc_clear(sizeof(frame_T));
+	frp = ALLOC_CLEAR_ONE(frame_T);
 	*frp = *curfrp;
 	curfrp->fr_layout = layout;
 	frp->fr_parent = curfrp;
@@ -3599,7 +3599,7 @@ win_alloc_firstwin(win_T *oldwin)
     static void
 new_frame(win_T *wp)
 {
-    frame_T *frp = (frame_T *)alloc_clear(sizeof(frame_T));
+    frame_T *frp = ALLOC_CLEAR_ONE(frame_T);
 
     wp->w_frame = frp;
     if (frp != NULL)
@@ -3634,7 +3634,7 @@ alloc_tabpage(void)
 # endif
 
 
-    tp = (tabpage_T *)alloc_clear(sizeof(tabpage_T));
+    tp = ALLOC_CLEAR_ONE(tabpage_T);
     if (tp == NULL)
 	return NULL;
 
@@ -4651,7 +4651,7 @@ win_alloc(win_T *after UNUSED, int hidde
     /*
      * allocate window structure and linesizes arrays
      */
-    new_wp = (win_T *)alloc_clear(sizeof(win_T));
+    new_wp = ALLOC_CLEAR_ONE(win_T);
     if (new_wp == NULL)
 	return NULL;
 
@@ -4980,7 +4980,7 @@ frame_remove(frame_T *frp)
 win_alloc_lines(win_T *wp)
 {
     wp->w_lines_valid = 0;
-    wp->w_lines = (wline_T *)alloc_clear(Rows * sizeof(wline_T));
+    wp->w_lines = ALLOC_CLEAR_MULT(wline_T, Rows );
     if (wp->w_lines == NULL)
 	return FAIL;
     return OK;
@@ -6362,7 +6362,7 @@ make_snapshot(int idx)
     static void
 make_snapshot_rec(frame_T *fr, frame_T **frp)
 {
-    *frp = (frame_T *)alloc_clear(sizeof(frame_T));
+    *frp = ALLOC_CLEAR_ONE(frame_T);
     if (*frp == NULL)
 	return;
     (*frp)->fr_layout = fr->fr_layout;
@@ -6671,7 +6671,7 @@ match_add(
     }
 
     /* Build new match. */
-    m = (matchitem_T *)alloc_clear(sizeof(matchitem_T));
+    m = ALLOC_CLEAR_ONE(matchitem_T);
     m->id = id;
     m->priority = prio;
     m->pattern = pat == NULL ? NULL : vim_strsave(pat);
@@ -7057,7 +7057,7 @@ win_id2wp(int id)
 	if (wp->w_id == id)
 	    return wp;
 #ifdef FEAT_TEXT_PROP
-    // popup windows are in a separate list
+    // popup windows are in separate lists
      FOR_ALL_TABPAGES(tp)
 	 for (wp = tp->tp_first_popupwin; wp != NULL; wp = wp->w_next)
 	     if (wp->w_id == id)