Mercurial > vim
comparison src/winclip.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 | 3147c7c2e86b |
comparison
equal
deleted
inserted
replaced
16824:1f6bb29738d2 | 16825:ce04ebdf26b8 |
---|---|
147 LPCSTR in, int inlen, | 147 LPCSTR in, int inlen, |
148 LPWSTR *out, int *outlen) | 148 LPWSTR *out, int *outlen) |
149 { | 149 { |
150 *outlen = MultiByteToWideChar(cp, flags, in, inlen, 0, 0); | 150 *outlen = MultiByteToWideChar(cp, flags, in, inlen, 0, 0); |
151 /* Add one one word to avoid a zero-length alloc(). */ | 151 /* Add one one word to avoid a zero-length alloc(). */ |
152 *out = (LPWSTR)alloc(sizeof(WCHAR) * (*outlen + 1)); | 152 *out = ALLOC_MULT(WCHAR, *outlen + 1); |
153 if (*out != NULL) | 153 if (*out != NULL) |
154 { | 154 { |
155 MultiByteToWideChar(cp, flags, in, inlen, *out, *outlen); | 155 MultiByteToWideChar(cp, flags, in, inlen, *out, *outlen); |
156 (*out)[*outlen] = 0; | 156 (*out)[*outlen] = 0; |
157 } | 157 } |
167 LPSTR *out, int *outlen, | 167 LPSTR *out, int *outlen, |
168 LPCSTR def, LPBOOL useddef) | 168 LPCSTR def, LPBOOL useddef) |
169 { | 169 { |
170 *outlen = WideCharToMultiByte(cp, flags, in, inlen, NULL, 0, def, useddef); | 170 *outlen = WideCharToMultiByte(cp, flags, in, inlen, NULL, 0, def, useddef); |
171 /* Add one one byte to avoid a zero-length alloc(). */ | 171 /* Add one one byte to avoid a zero-length alloc(). */ |
172 *out = (LPSTR)alloc(*outlen + 1); | 172 *out = alloc(*outlen + 1); |
173 if (*out != NULL) | 173 if (*out != NULL) |
174 { | 174 { |
175 WideCharToMultiByte(cp, flags, in, inlen, *out, *outlen, def, useddef); | 175 WideCharToMultiByte(cp, flags, in, inlen, *out, *outlen, def, useddef); |
176 (*out)[*outlen] = 0; | 176 (*out)[*outlen] = 0; |
177 } | 177 } |
510 /* Convert the text for CF_TEXT to Active codepage. Otherwise it's | 510 /* Convert the text for CF_TEXT to Active codepage. Otherwise it's |
511 * p_enc, which has no relation to the Active codepage. */ | 511 * p_enc, which has no relation to the Active codepage. */ |
512 metadata.txtlen = WideCharToMultiByte(GetACP(), 0, out, len, | 512 metadata.txtlen = WideCharToMultiByte(GetACP(), 0, out, len, |
513 NULL, 0, 0, 0); | 513 NULL, 0, 0, 0); |
514 vim_free(str); | 514 vim_free(str); |
515 str = (char_u *)alloc(metadata.txtlen == 0 ? 1 : metadata.txtlen); | 515 str = alloc(metadata.txtlen == 0 ? 1 : metadata.txtlen); |
516 if (str == NULL) | 516 if (str == NULL) |
517 { | 517 { |
518 vim_free(out); | 518 vim_free(out); |
519 return; /* out of memory */ | 519 return; /* out of memory */ |
520 } | 520 } |
652 return NULL; | 652 return NULL; |
653 } | 653 } |
654 convert_setup(&conv, NULL, NULL); | 654 convert_setup(&conv, NULL, NULL); |
655 | 655 |
656 length = utf8_to_utf16(str, *lenp, NULL, NULL); | 656 length = utf8_to_utf16(str, *lenp, NULL, NULL); |
657 ret = (WCHAR *)alloc((length + 1) * sizeof(WCHAR)); | 657 ret = ALLOC_MULT(WCHAR, length + 1); |
658 if (ret != NULL) | 658 if (ret != NULL) |
659 { | 659 { |
660 utf8_to_utf16(str, *lenp, (short_u *)ret, NULL); | 660 utf8_to_utf16(str, *lenp, (short_u *)ret, NULL); |
661 ret[length] = 0; | 661 ret[length] = 0; |
662 } | 662 } |