comparison src/channel.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 fc58fee685e2
children a836d122231a
comparison
equal deleted inserted replaced
16824:1f6bb29738d2 16825:ce04ebdf26b8
292 */ 292 */
293 channel_T * 293 channel_T *
294 add_channel(void) 294 add_channel(void)
295 { 295 {
296 ch_part_T part; 296 ch_part_T part;
297 channel_T *channel = (channel_T *)alloc_clear(sizeof(channel_T)); 297 channel_T *channel = ALLOC_CLEAR_ONE(channel_T);
298 298
299 if (channel == NULL) 299 if (channel == NULL)
300 return NULL; 300 return NULL;
301 301
302 channel->ch_id = next_ch_id++; 302 channel->ch_id = next_ch_id++;
1352 char_u *callback, 1352 char_u *callback,
1353 partial_T *partial, 1353 partial_T *partial,
1354 int id) 1354 int id)
1355 { 1355 {
1356 cbq_T *head = &channel->ch_part[part].ch_cb_head; 1356 cbq_T *head = &channel->ch_part[part].ch_cb_head;
1357 cbq_T *item = (cbq_T *)alloc(sizeof(cbq_T)); 1357 cbq_T *item = ALLOC_ONE(cbq_T);
1358 1358
1359 if (item != NULL) 1359 if (item != NULL)
1360 { 1360 {
1361 item->cq_partial = partial; 1361 item->cq_partial = partial;
1362 if (partial != NULL) 1362 if (partial != NULL)
1873 readq_T *node; 1873 readq_T *node;
1874 readq_T *head = &channel->ch_part[part].ch_head; 1874 readq_T *head = &channel->ch_part[part].ch_head;
1875 char_u *p; 1875 char_u *p;
1876 int i; 1876 int i;
1877 1877
1878 node = (readq_T *)alloc(sizeof(readq_T)); 1878 node = ALLOC_ONE(readq_T);
1879 if (node == NULL) 1879 if (node == NULL)
1880 return FAIL; /* out of memory */ 1880 return FAIL; /* out of memory */
1881 /* A NUL is added at the end, because netbeans code expects that. 1881 /* A NUL is added at the end, because netbeans code expects that.
1882 * Otherwise a NUL may appear inside the text. */ 1882 * Otherwise a NUL may appear inside the text. */
1883 node->rq_buffer = alloc(len + 1); 1883 node->rq_buffer = alloc(len + 1);
2022 listtv.vval.v_list->lv_len); 2022 listtv.vval.v_list->lv_len);
2023 clear_tv(&listtv); 2023 clear_tv(&listtv);
2024 } 2024 }
2025 else 2025 else
2026 { 2026 {
2027 item = (jsonq_T *)alloc(sizeof(jsonq_T)); 2027 item = ALLOC_ONE(jsonq_T);
2028 if (item == NULL) 2028 if (item == NULL)
2029 clear_tv(&listtv); 2029 clear_tv(&listtv);
2030 else 2030 else
2031 { 2031 {
2032 item->jq_no_callback = FALSE; 2032 item->jq_no_callback = FALSE;
2221 item = NULL; 2221 item = NULL;
2222 else while (item != NULL && item->jq_no_callback) 2222 else while (item != NULL && item->jq_no_callback)
2223 /* append after the last item that was pushed back */ 2223 /* append after the last item that was pushed back */
2224 item = item->jq_next; 2224 item = item->jq_next;
2225 2225
2226 newitem = (jsonq_T *)alloc(sizeof(jsonq_T)); 2226 newitem = ALLOC_ONE(jsonq_T);
2227 if (newitem == NULL) 2227 if (newitem == NULL)
2228 clear_tv(rettv); 2228 clear_tv(rettv);
2229 else 2229 else
2230 { 2230 {
2231 newitem->jq_value = alloc_tv(); 2231 newitem->jq_value = alloc_tv();
3919 last->wq_ga.ga_len += len; 3919 last->wq_ga.ga_len += len;
3920 } 3920 }
3921 } 3921 }
3922 else 3922 else
3923 { 3923 {
3924 writeq_T *last = (writeq_T *)alloc(sizeof(writeq_T)); 3924 writeq_T *last = ALLOC_ONE(writeq_T);
3925 3925
3926 if (last != NULL) 3926 if (last != NULL)
3927 { 3927 {
3928 last->wq_prev = wq->wq_prev; 3928 last->wq_prev = wq->wq_prev;
3929 last->wq_next = NULL; 3929 last->wq_next = NULL;
5591 job_T * 5591 job_T *
5592 job_alloc(void) 5592 job_alloc(void)
5593 { 5593 {
5594 job_T *job; 5594 job_T *job;
5595 5595
5596 job = (job_T *)alloc_clear(sizeof(job_T)); 5596 job = ALLOC_CLEAR_ONE(job_T);
5597 if (job != NULL) 5597 if (job != NULL)
5598 { 5598 {
5599 job->jv_refcount = 1; 5599 job->jv_refcount = 1;
5600 job->jv_stoponexit = vim_strsave((char_u *)"term"); 5600 job->jv_stoponexit = vim_strsave((char_u *)"term");
5601 5601
5820 if (argv_arg != NULL) 5820 if (argv_arg != NULL)
5821 { 5821 {
5822 /* Make a copy of argv_arg for job->jv_argv. */ 5822 /* Make a copy of argv_arg for job->jv_argv. */
5823 for (i = 0; argv_arg[i] != NULL; i++) 5823 for (i = 0; argv_arg[i] != NULL; i++)
5824 argc++; 5824 argc++;
5825 argv = (char **)alloc(sizeof(char *) * (argc + 1)); 5825 argv = ALLOC_MULT(char *, argc + 1);
5826 if (argv == NULL) 5826 if (argv == NULL)
5827 goto theend; 5827 goto theend;
5828 for (i = 0; i < argc; i++) 5828 for (i = 0; i < argc; i++)
5829 argv[i] = (char *)vim_strsave((char_u *)argv_arg[i]); 5829 argv[i] = (char *)vim_strsave((char_u *)argv_arg[i]);
5830 argv[argc] = NULL; 5830 argv[argc] = NULL;