Mercurial > vim
diff src/memfile.c @ 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 | b1b7c7a31679 |
children | f41b55f9357c |
line wrap: on
line diff
--- 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;