Mercurial > vim
comparison src/spell.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 | 695d9ef00b03 |
children | 26e8d42987ca |
comparison
equal
deleted
inserted
replaced
16824:1f6bb29738d2 | 16825:ce04ebdf26b8 |
---|---|
1897 slang_T * | 1897 slang_T * |
1898 slang_alloc(char_u *lang) | 1898 slang_alloc(char_u *lang) |
1899 { | 1899 { |
1900 slang_T *lp; | 1900 slang_T *lp; |
1901 | 1901 |
1902 lp = (slang_T *)alloc_clear(sizeof(slang_T)); | 1902 lp = ALLOC_CLEAR_ONE(slang_T); |
1903 if (lp != NULL) | 1903 if (lp != NULL) |
1904 { | 1904 { |
1905 if (lang != NULL) | 1905 if (lang != NULL) |
1906 lp->sl_name = vim_strsave(lang); | 1906 lp->sl_name = vim_strsave(lang); |
1907 ga_init2(&lp->sl_rep, sizeof(fromto_T), 10); | 1907 ga_init2(&lp->sl_rep, sizeof(fromto_T), 10); |
2081 | 2081 |
2082 hash = hash_hash(p); | 2082 hash = hash_hash(p); |
2083 hi = hash_lookup(&lp->sl_wordcount, p, hash); | 2083 hi = hash_lookup(&lp->sl_wordcount, p, hash); |
2084 if (HASHITEM_EMPTY(hi)) | 2084 if (HASHITEM_EMPTY(hi)) |
2085 { | 2085 { |
2086 wc = (wordcount_T *)alloc(sizeof(wordcount_T) + STRLEN(p)); | 2086 wc = alloc(sizeof(wordcount_T) + STRLEN(p)); |
2087 if (wc == NULL) | 2087 if (wc == NULL) |
2088 return; | 2088 return; |
2089 STRCPY(wc->wc_word, p); | 2089 STRCPY(wc->wc_word, p); |
2090 wc->wc_count = count; | 2090 wc->wc_count = count; |
2091 hash_add_item(&lp->sl_wordcount, hi, wc->wc_word, hash); | 2091 hash_add_item(&lp->sl_wordcount, hi, wc->wc_word, hash); |
2881 buf_T * | 2881 buf_T * |
2882 open_spellbuf(void) | 2882 open_spellbuf(void) |
2883 { | 2883 { |
2884 buf_T *buf; | 2884 buf_T *buf; |
2885 | 2885 |
2886 buf = (buf_T *)alloc_clear(sizeof(buf_T)); | 2886 buf = ALLOC_CLEAR_ONE(buf_T); |
2887 if (buf != NULL) | 2887 if (buf != NULL) |
2888 { | 2888 { |
2889 buf->b_spell = TRUE; | 2889 buf->b_spell = TRUE; |
2890 buf->b_p_swf = TRUE; /* may create a swap file */ | 2890 buf->b_p_swf = TRUE; /* may create a swap file */ |
2891 #ifdef FEAT_CRYPT | 2891 #ifdef FEAT_CRYPT |
6221 */ | 6221 */ |
6222 hash = hash_hash(goodword); | 6222 hash = hash_hash(goodword); |
6223 hi = hash_lookup(&slang->sl_sounddone, goodword, hash); | 6223 hi = hash_lookup(&slang->sl_sounddone, goodword, hash); |
6224 if (HASHITEM_EMPTY(hi)) | 6224 if (HASHITEM_EMPTY(hi)) |
6225 { | 6225 { |
6226 sft = (sftword_T *)alloc(sizeof(sftword_T) + STRLEN(goodword)); | 6226 sft = alloc(sizeof(sftword_T) + STRLEN(goodword)); |
6227 if (sft != NULL) | 6227 if (sft != NULL) |
6228 { | 6228 { |
6229 sft->sft_score = score; | 6229 sft->sft_score = score; |
6230 STRCPY(sft->sft_word, goodword); | 6230 STRCPY(sft->sft_word, goodword); |
6231 hash_add_item(&slang->sl_sounddone, hi, sft->sft_word, hash); | 6231 hash_add_item(&slang->sl_sounddone, hi, sft->sft_word, hash); |
7818 goodlen = (int)STRLEN(goodword) + 1; | 7818 goodlen = (int)STRLEN(goodword) + 1; |
7819 } | 7819 } |
7820 | 7820 |
7821 /* We use "cnt" as an array: CNT(badword_idx, goodword_idx). */ | 7821 /* We use "cnt" as an array: CNT(badword_idx, goodword_idx). */ |
7822 #define CNT(a, b) cnt[(a) + (b) * (badlen + 1)] | 7822 #define CNT(a, b) cnt[(a) + (b) * (badlen + 1)] |
7823 cnt = (int *)alloc(sizeof(int) * (badlen + 1) * (goodlen + 1)); | 7823 cnt = ALLOC_MULT(int, (badlen + 1) * (goodlen + 1)); |
7824 if (cnt == NULL) | 7824 if (cnt == NULL) |
7825 return 0; /* out of memory */ | 7825 return 0; /* out of memory */ |
7826 | 7826 |
7827 CNT(0, 0) = 0; | 7827 CNT(0, 0) = 0; |
7828 for (j = 1; j <= goodlen; ++j) | 7828 for (j = 1; j <= goodlen; ++j) |