Mercurial > vim
comparison src/memline.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 | 98ca522e6453 |
children | d5e1e09a829f |
comparison
equal
deleted
inserted
replaced
16824:1f6bb29738d2 | 16825:ce04ebdf26b8 |
---|---|
1187 | 1187 |
1188 /* | 1188 /* |
1189 * Allocate a buffer structure for the swap file that is used for recovery. | 1189 * Allocate a buffer structure for the swap file that is used for recovery. |
1190 * Only the memline and crypt information in it are really used. | 1190 * Only the memline and crypt information in it are really used. |
1191 */ | 1191 */ |
1192 buf = (buf_T *)alloc(sizeof(buf_T)); | 1192 buf = ALLOC_ONE(buf_T); |
1193 if (buf == NULL) | 1193 if (buf == NULL) |
1194 goto theend; | 1194 goto theend; |
1195 | 1195 |
1196 /* | 1196 /* |
1197 * init fields in memline struct | 1197 * init fields in memline struct |
1909 (char_u *)".swp", TRUE | 1909 (char_u *)".swp", TRUE |
1910 #endif | 1910 #endif |
1911 ); | 1911 ); |
1912 if (swapname != NULL) | 1912 if (swapname != NULL) |
1913 { | 1913 { |
1914 if (mch_stat((char *)swapname, &st) != -1) /* It exists! */ | 1914 if (mch_stat((char *)swapname, &st) != -1) // It exists! |
1915 { | 1915 { |
1916 files = (char_u **)alloc(sizeof(char_u *)); | 1916 files = ALLOC_ONE(char_u *); |
1917 if (files != NULL) | 1917 if (files != NULL) |
1918 { | 1918 { |
1919 files[0] = swapname; | 1919 files[0] = swapname; |
1920 swapname = NULL; | 1920 swapname = NULL; |
1921 num_files = 1; | 1921 num_files = 1; |
4203 /* may have to increase the stack size */ | 4203 /* may have to increase the stack size */ |
4204 if (top == buf->b_ml.ml_stack_size) | 4204 if (top == buf->b_ml.ml_stack_size) |
4205 { | 4205 { |
4206 CHECK(top > 0, _("Stack size increases")); /* more than 5 levels??? */ | 4206 CHECK(top > 0, _("Stack size increases")); /* more than 5 levels??? */ |
4207 | 4207 |
4208 newstack = (infoptr_T *)alloc(sizeof(infoptr_T) * | 4208 newstack = ALLOC_MULT(infoptr_T, buf->b_ml.ml_stack_size + STACK_INCR); |
4209 (buf->b_ml.ml_stack_size + STACK_INCR)); | |
4210 if (newstack == NULL) | 4209 if (newstack == NULL) |
4211 return -1; | 4210 return -1; |
4212 if (top > 0) | 4211 if (top > 0) |
4213 mch_memmove(newstack, buf->b_ml.ml_stack, | 4212 mch_memmove(newstack, buf->b_ml.ml_stack, |
4214 (size_t)top * sizeof(infoptr_T)); | 4213 (size_t)top * sizeof(infoptr_T)); |
5233 | 5232 |
5234 state = ml_crypt_prepare(mfp, offset, FALSE); | 5233 state = ml_crypt_prepare(mfp, offset, FALSE); |
5235 if (state == NULL) | 5234 if (state == NULL) |
5236 return data; | 5235 return data; |
5237 | 5236 |
5238 new_data = (char_u *)alloc(size); | 5237 new_data = alloc(size); |
5239 if (new_data == NULL) | 5238 if (new_data == NULL) |
5240 return NULL; | 5239 return NULL; |
5241 head_end = (char_u *)(&dp->db_index[dp->db_line_count]); | 5240 head_end = (char_u *)(&dp->db_index[dp->db_line_count]); |
5242 text_start = (char_u *)dp + dp->db_txt_start; | 5241 text_start = (char_u *)dp + dp->db_txt_start; |
5243 text_len = size - dp->db_txt_start; | 5242 text_len = size - dp->db_txt_start; |
5373 | 5372 |
5374 if (buf->b_ml.ml_usedchunks == -1 || len == 0) | 5373 if (buf->b_ml.ml_usedchunks == -1 || len == 0) |
5375 return; | 5374 return; |
5376 if (buf->b_ml.ml_chunksize == NULL) | 5375 if (buf->b_ml.ml_chunksize == NULL) |
5377 { | 5376 { |
5378 buf->b_ml.ml_chunksize = | 5377 buf->b_ml.ml_chunksize = ALLOC_MULT(chunksize_T, 100); |
5379 (chunksize_T *)alloc(sizeof(chunksize_T) * 100); | |
5380 if (buf->b_ml.ml_chunksize == NULL) | 5378 if (buf->b_ml.ml_chunksize == NULL) |
5381 { | 5379 { |
5382 buf->b_ml.ml_usedchunks = -1; | 5380 buf->b_ml.ml_usedchunks = -1; |
5383 return; | 5381 return; |
5384 } | 5382 } |