comparison src/gui_w32.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 ce562b9f702e
comparison
equal deleted inserted replaced
16824:1f6bb29738d2 16825:ce04ebdf26b8
3118 if (font_name == NULL) 3118 if (font_name == NULL)
3119 return NULL; 3119 return NULL;
3120 charset_name = charset_id2name((int)lf.lfCharSet); 3120 charset_name = charset_id2name((int)lf.lfCharSet);
3121 quality_name = quality_id2name((int)lf.lfQuality); 3121 quality_name = quality_id2name((int)lf.lfQuality);
3122 3122
3123 res = (char *)alloc(strlen(font_name) + 30 3123 res = alloc(strlen(font_name) + 30
3124 + (charset_name == NULL ? 0 : strlen(charset_name) + 2) 3124 + (charset_name == NULL ? 0 : strlen(charset_name) + 2)
3125 + (quality_name == NULL ? 0 : strlen(quality_name) + 2)); 3125 + (quality_name == NULL ? 0 : strlen(quality_name) + 2));
3126 if (res != NULL) 3126 if (res != NULL)
3127 { 3127 {
3128 p = res; 3128 p = res;
3637 DragQueryPoint(hDrop, &pt); 3637 DragQueryPoint(hDrop, &pt);
3638 MapWindowPoints(s_hwnd, s_textArea, &pt, 1); 3638 MapWindowPoints(s_hwnd, s_textArea, &pt, 1);
3639 3639
3640 reset_VIsual(); 3640 reset_VIsual();
3641 3641
3642 fnames = (char_u **)alloc(cFiles * sizeof(char_u *)); 3642 fnames = ALLOC_MULT(char_u *, cFiles);
3643 3643
3644 if (fnames != NULL) 3644 if (fnames != NULL)
3645 for (i = 0; i < cFiles; ++i) 3645 for (i = 0; i < cFiles; ++i)
3646 { 3646 {
3647 if (DragQueryFileW(hDrop, i, wszFile, BUFPATHLEN) > 0) 3647 if (DragQueryFileW(hDrop, i, wszFile, BUFPATHLEN) > 0)
4914 goto error; 4914 goto error;
4915 wsession = enc_to_utf16(session, NULL); 4915 wsession = enc_to_utf16(session, NULL);
4916 if (wsession == NULL) 4916 if (wsession == NULL)
4917 goto error; 4917 goto error;
4918 len = (int)wcslen(wsession) * 2 + 27 + 1; 4918 len = (int)wcslen(wsession) * 2 + 27 + 1;
4919 cmd = (LPWSTR)alloc(len * (int)sizeof(WCHAR)); 4919 cmd = ALLOC_MULT(WCHAR, len);
4920 if (cmd == NULL) 4920 if (cmd == NULL)
4921 { 4921 {
4922 vim_free(wsession); 4922 vim_free(wsession);
4923 goto error; 4923 goto error;
4924 } 4924 }
4940 else 4940 else
4941 warg = L""; 4941 warg = L"";
4942 4942
4943 // Set up the new command line. 4943 // Set up the new command line.
4944 len = (int)wcslen(name) + (int)wcslen(cmd) + (int)wcslen(warg) + 4; 4944 len = (int)wcslen(name) + (int)wcslen(cmd) + (int)wcslen(warg) + 4;
4945 newcmd = (LPWSTR)alloc(len * (int)sizeof(WCHAR)); 4945 newcmd = ALLOC_MULT(WCHAR, len);
4946 if (newcmd == NULL) 4946 if (newcmd == NULL)
4947 goto error; 4947 goto error;
4948 _snwprintf(newcmd, len, L"\"%s\"%s %s", name, cmd, warg); 4948 _snwprintf(newcmd, len, L"\"%s\"%s %s", name, cmd, warg);
4949 4949
4950 // Spawn a new GUI process. 4950 // Spawn a new GUI process.
5291 */ 5291 */
5292 s_findrep_msg = RegisterWindowMessage(FINDMSGSTRING); 5292 s_findrep_msg = RegisterWindowMessage(FINDMSGSTRING);
5293 5293
5294 /* Initialise the struct */ 5294 /* Initialise the struct */
5295 s_findrep_struct.lStructSize = sizeof(s_findrep_struct); 5295 s_findrep_struct.lStructSize = sizeof(s_findrep_struct);
5296 s_findrep_struct.lpstrFindWhat = 5296 s_findrep_struct.lpstrFindWhat = ALLOC_MULT(WCHAR, MSWIN_FR_BUFSIZE);
5297 (LPWSTR)alloc(MSWIN_FR_BUFSIZE * sizeof(WCHAR));
5298 s_findrep_struct.lpstrFindWhat[0] = NUL; 5297 s_findrep_struct.lpstrFindWhat[0] = NUL;
5299 s_findrep_struct.lpstrReplaceWith = 5298 s_findrep_struct.lpstrReplaceWith = ALLOC_MULT(WCHAR, MSWIN_FR_BUFSIZE);
5300 (LPWSTR)alloc(MSWIN_FR_BUFSIZE * sizeof(WCHAR));
5301 s_findrep_struct.lpstrReplaceWith[0] = NUL; 5299 s_findrep_struct.lpstrReplaceWith[0] = NUL;
5302 s_findrep_struct.wFindWhatLen = MSWIN_FR_BUFSIZE; 5300 s_findrep_struct.wFindWhatLen = MSWIN_FR_BUFSIZE;
5303 s_findrep_struct.wReplaceWithLen = MSWIN_FR_BUFSIZE; 5301 s_findrep_struct.wReplaceWithLen = MSWIN_FR_BUFSIZE;
5304 #endif 5302 #endif
5305 5303
5611 return NULL; /* empty */ 5609 return NULL; /* empty */
5612 5610
5613 if (ret > 0) 5611 if (ret > 0)
5614 { 5612 {
5615 /* Allocate the requested buffer plus space for the NUL character. */ 5613 /* Allocate the requested buffer plus space for the NUL character. */
5616 wbuf = (LPWSTR)alloc(ret + sizeof(WCHAR)); 5614 wbuf = alloc(ret + sizeof(WCHAR));
5617 if (wbuf != NULL) 5615 if (wbuf != NULL)
5618 { 5616 {
5619 pImmGetCompositionStringW(hIMC, GCS, wbuf, ret); 5617 pImmGetCompositionStringW(hIMC, GCS, wbuf, ret);
5620 *lenp = ret / sizeof(WCHAR); 5618 *lenp = ret / sizeof(WCHAR);
5621 } 5619 }
6056 vim_free(padding); 6054 vim_free(padding);
6057 pad_size = Columns; 6055 pad_size = Columns;
6058 6056
6059 /* Don't give an out-of-memory message here, it would call us 6057 /* Don't give an out-of-memory message here, it would call us
6060 * recursively. */ 6058 * recursively. */
6061 padding = (int *)lalloc(pad_size * sizeof(int), FALSE); 6059 padding = LALLOC_MULT(sizeof(int), pad_size);
6062 if (padding != NULL) 6060 if (padding != NULL)
6063 for (i = 0; i < pad_size; i++) 6061 for (i = 0; i < pad_size; i++)
6064 padding[i] = gui.char_width; 6062 padding[i] = gui.char_width;
6065 } 6063 }
6066 6064
6093 || (enc_codepage > 0 && (int)GetACP() != enc_codepage) 6091 || (enc_codepage > 0 && (int)GetACP() != enc_codepage)
6094 || enc_latin9) 6092 || enc_latin9)
6095 && (unicodebuf == NULL || len > unibuflen)) 6093 && (unicodebuf == NULL || len > unibuflen))
6096 { 6094 {
6097 vim_free(unicodebuf); 6095 vim_free(unicodebuf);
6098 unicodebuf = (WCHAR *)lalloc(len * sizeof(WCHAR), FALSE); 6096 unicodebuf = LALLOC_MULT(WCHAR, len);
6099 6097
6100 vim_free(unicodepdy); 6098 vim_free(unicodepdy);
6101 unicodepdy = (int *)lalloc(len * sizeof(int), FALSE); 6099 unicodepdy = LALLOC_MULT(int, len);
6102 6100
6103 unibuflen = len; 6101 unibuflen = len;
6104 } 6102 }
6105 6103
6106 if (enc_utf8 && n < len && unicodebuf != NULL) 6104 if (enc_utf8 && n < len && unicodebuf != NULL)
6652 return TRUE; 6650 return TRUE;
6653 6651
6654 /* If the edit box exists, copy the string. */ 6652 /* If the edit box exists, copy the string. */
6655 if (s_textfield != NULL) 6653 if (s_textfield != NULL)
6656 { 6654 {
6657 WCHAR *wp = (WCHAR *)alloc(IOSIZE * sizeof(WCHAR)); 6655 WCHAR *wp = ALLOC_MULT(WCHAR, IOSIZE);
6658 char_u *p; 6656 char_u *p;
6659 6657
6660 GetDlgItemTextW(hwnd, DLG_NONBUTTON_CONTROL + 2, wp, IOSIZE); 6658 GetDlgItemTextW(hwnd, DLG_NONBUTTON_CONTROL + 2, wp, IOSIZE);
6661 p = utf16_to_enc(wp, NULL); 6659 p = utf16_to_enc(wp, NULL);
6662 vim_strncpy(s_textfield, p, IOSIZE); 6660 vim_strncpy(s_textfield, p, IOSIZE);
6801 } 6799 }
6802 if (dfltbutton >= numButtons) 6800 if (dfltbutton >= numButtons)
6803 dfltbutton = -1; 6801 dfltbutton = -1;
6804 6802
6805 /* Allocate array to hold the width of each button */ 6803 /* Allocate array to hold the width of each button */
6806 buttonWidths = (int *)alloc(numButtons * sizeof(int)); 6804 buttonWidths = ALLOC_MULT(int, numButtons);
6807 if (buttonWidths == NULL) 6805 if (buttonWidths == NULL)
6808 return -1; 6806 return -1;
6809 6807
6810 /* Allocate array to hold the X position of each button */ 6808 /* Allocate array to hold the X position of each button */
6811 buttonPositions = (int *)alloc(numButtons * sizeof(int)); 6809 buttonPositions = ALLOC_MULT(int, numButtons);
6812 if (buttonPositions == NULL) 6810 if (buttonPositions == NULL)
6813 return -1; 6811 return -1;
6814 6812
6815 /* 6813 /*
6816 * Calculate how big the dialog must be. 6814 * Calculate how big the dialog must be.
8230 } 8228 }
8231 #endif 8229 #endif
8232 } 8230 }
8233 8231
8234 psign = NULL; 8232 psign = NULL;
8235 if (sign.hImage && (psign = (signicon_t *)alloc(sizeof(signicon_t))) 8233 if (sign.hImage && (psign = ALLOC_ONE(signicon_t)) != NULL)
8236 != NULL)
8237 *psign = sign; 8234 *psign = sign;
8238 8235
8239 if (!psign) 8236 if (!psign)
8240 { 8237 {
8241 if (sign.hImage) 8238 if (sign.hImage)
8359 if (multiline_balloon_available() == TRUE) 8356 if (multiline_balloon_available() == TRUE)
8360 ToolInfoSize = sizeof(TOOLINFOW_NEW); 8357 ToolInfoSize = sizeof(TOOLINFOW_NEW);
8361 else 8358 else
8362 ToolInfoSize = sizeof(TOOLINFOW); 8359 ToolInfoSize = sizeof(TOOLINFOW);
8363 8360
8364 pti = (TOOLINFOW *)alloc(ToolInfoSize); 8361 pti = alloc(ToolInfoSize);
8365 if (pti == NULL) 8362 if (pti == NULL)
8366 return; 8363 return;
8367 8364
8368 beval->balloon = CreateWindowExW(WS_EX_TOPMOST, TOOLTIPS_CLASSW, 8365 beval->balloon = CreateWindowExW(WS_EX_TOPMOST, TOOLTIPS_CLASSW,
8369 NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, 8366 NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
8530 { 8527 {
8531 iemsg(_("E232: Cannot create BalloonEval with both message and callback")); 8528 iemsg(_("E232: Cannot create BalloonEval with both message and callback"));
8532 return NULL; 8529 return NULL;
8533 } 8530 }
8534 8531
8535 beval = (BalloonEval *)alloc_clear(sizeof(BalloonEval)); 8532 beval = ALLOC_CLEAR_ONE(BalloonEval);
8536 if (beval != NULL) 8533 if (beval != NULL)
8537 { 8534 {
8538 beval->target = s_textArea; 8535 beval->target = s_textArea;
8539 8536
8540 beval->showState = ShS_NEUTRAL; 8537 beval->showState = ShS_NEUTRAL;