Mercurial > vim
comparison src/terminal.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 | a5e3509b33ca |
comparison
equal
deleted
inserted
replaced
16824:1f6bb29738d2 | 16825:ce04ebdf26b8 |
---|---|
411 { | 411 { |
412 emsg(_(e_invarg)); | 412 emsg(_(e_invarg)); |
413 return NULL; | 413 return NULL; |
414 } | 414 } |
415 | 415 |
416 term = (term_T *)alloc_clear(sizeof(term_T)); | 416 term = ALLOC_CLEAR_ONE(term_T); |
417 if (term == NULL) | 417 if (term == NULL) |
418 return NULL; | 418 return NULL; |
419 term->tl_dirty_row_end = MAX_ROW; | 419 term->tl_dirty_row_end = MAX_ROW; |
420 term->tl_cursor_visible = TRUE; | 420 term->tl_cursor_visible = TRUE; |
421 term->tl_cursor_shape = VTERM_PROP_CURSORSHAPE_BLOCK; | 421 term->tl_cursor_shape = VTERM_PROP_CURSORSHAPE_BLOCK; |
1628 } | 1628 } |
1629 | 1629 |
1630 if (len == 0) | 1630 if (len == 0) |
1631 p = NULL; | 1631 p = NULL; |
1632 else | 1632 else |
1633 p = (cellattr_T *)alloc(sizeof(cellattr_T) * len); | 1633 p = ALLOC_MULT(cellattr_T, len); |
1634 if ((p != NULL || len == 0) | 1634 if ((p != NULL || len == 0) |
1635 && ga_grow(&term->tl_scrollback, 1) == OK) | 1635 && ga_grow(&term->tl_scrollback, 1) == OK) |
1636 { | 1636 { |
1637 garray_T ga; | 1637 garray_T ga; |
1638 int width; | 1638 int width; |
2882 else | 2882 else |
2883 cell2cellattr(&cells[i], &fill_attr); | 2883 cell2cellattr(&cells[i], &fill_attr); |
2884 | 2884 |
2885 ga_init2(&ga, 1, 100); | 2885 ga_init2(&ga, 1, 100); |
2886 if (len > 0) | 2886 if (len > 0) |
2887 p = (cellattr_T *)alloc(sizeof(cellattr_T) * len); | 2887 p = ALLOC_MULT(cellattr_T, len); |
2888 if (p != NULL) | 2888 if (p != NULL) |
2889 { | 2889 { |
2890 for (col = 0; col < len; col += cells[col].width) | 2890 for (col = 0; col < len; col += cells[col].width) |
2891 { | 2891 { |
2892 if (ga_grow(&ga, MB_MAXBYTES) == FAIL) | 2892 if (ga_grow(&ga, MB_MAXBYTES) == FAIL) |
4933 } | 4933 } |
4934 } | 4934 } |
4935 else | 4935 else |
4936 { | 4936 { |
4937 size_t size = sizeof(sb_line_T) * term->tl_scrollback.ga_len; | 4937 size_t size = sizeof(sb_line_T) * term->tl_scrollback.ga_len; |
4938 sb_line_T *temp = (sb_line_T *)alloc(size); | 4938 sb_line_T *temp = alloc(size); |
4939 | 4939 |
4940 /* need to copy cell properties into temp memory */ | 4940 /* need to copy cell properties into temp memory */ |
4941 if (temp != NULL) | 4941 if (temp != NULL) |
4942 { | 4942 { |
4943 mch_memmove(temp, term->tl_scrollback.ga_data, size); | 4943 mch_memmove(temp, term->tl_scrollback.ga_data, size); |
5798 | 5798 |
5799 if (cmd_wchar != NULL) | 5799 if (cmd_wchar != NULL) |
5800 { | 5800 { |
5801 /* Request by CreateProcessW */ | 5801 /* Request by CreateProcessW */ |
5802 breq = wcslen(cmd_wchar) + 1 + 1; /* Addition of NUL by API */ | 5802 breq = wcslen(cmd_wchar) + 1 + 1; /* Addition of NUL by API */ |
5803 cmd_wchar_copy = (PWSTR)alloc(breq * sizeof(WCHAR)); | 5803 cmd_wchar_copy = ALLOC_MULT(WCHAR, breq); |
5804 wcsncpy(cmd_wchar_copy, cmd_wchar, breq - 1); | 5804 wcsncpy(cmd_wchar_copy, cmd_wchar, breq - 1); |
5805 } | 5805 } |
5806 | 5806 |
5807 ga_clear(&ga_cmd); | 5807 ga_clear(&ga_cmd); |
5808 if (cmd_wchar == NULL) | 5808 if (cmd_wchar == NULL) |
5827 | 5827 |
5828 term->tl_siex.StartupInfo.cb = sizeof(term->tl_siex); | 5828 term->tl_siex.StartupInfo.cb = sizeof(term->tl_siex); |
5829 | 5829 |
5830 /* Set up pipe inheritance safely: Vista or later. */ | 5830 /* Set up pipe inheritance safely: Vista or later. */ |
5831 pInitializeProcThreadAttributeList(NULL, 1, 0, &breq); | 5831 pInitializeProcThreadAttributeList(NULL, 1, 0, &breq); |
5832 term->tl_siex.lpAttributeList = | 5832 term->tl_siex.lpAttributeList = alloc(breq); |
5833 (PPROC_THREAD_ATTRIBUTE_LIST)alloc(breq); | |
5834 if (!term->tl_siex.lpAttributeList) | 5833 if (!term->tl_siex.lpAttributeList) |
5835 goto failed; | 5834 goto failed; |
5836 if (!pInitializeProcThreadAttributeList(term->tl_siex.lpAttributeList, 1, | 5835 if (!pInitializeProcThreadAttributeList(term->tl_siex.lpAttributeList, 1, |
5837 0, &breq)) | 5836 0, &breq)) |
5838 goto failed; | 5837 goto failed; |