comparison src/option.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 306766ed0f70
children 283037126560
comparison
equal deleted inserted replaced
16824:1f6bb29738d2 16825:ce04ebdf26b8
7964 vim_free(wp->w_p_cc_cols); 7964 vim_free(wp->w_p_cc_cols);
7965 if (count == 0) 7965 if (count == 0)
7966 wp->w_p_cc_cols = NULL; 7966 wp->w_p_cc_cols = NULL;
7967 else 7967 else
7968 { 7968 {
7969 wp->w_p_cc_cols = (int *)alloc(sizeof(int) * (count + 1)); 7969 wp->w_p_cc_cols = ALLOC_MULT(int, count + 1);
7970 if (wp->w_p_cc_cols != NULL) 7970 if (wp->w_p_cc_cols != NULL)
7971 { 7971 {
7972 /* sort the columns for faster usage on screen redraw inside 7972 /* sort the columns for faster usage on screen redraw inside
7973 * win_line() */ 7973 * win_line() */
7974 qsort(color_cols, count, sizeof(int), int_cmp); 7974 qsort(color_cols, count, sizeof(int), int_cmp);
10104 int len; 10104 int len;
10105 10105
10106 #define INC 20 10106 #define INC 20
10107 #define GAP 3 10107 #define GAP 3
10108 10108
10109 items = (struct vimoption **)alloc(sizeof(struct vimoption *) 10109 items = ALLOC_MULT(struct vimoption *, PARAM_COUNT);
10110 * PARAM_COUNT);
10111 if (items == NULL) 10110 if (items == NULL)
10112 return; 10111 return;
10113 10112
10114 /* Highlight title */ 10113 /* Highlight title */
10115 if (all == 2) 10114 if (all == 2)
11996 *num_file = num_normal; 11995 *num_file = num_normal;
11997 else if (num_term > 0) 11996 else if (num_term > 0)
11998 *num_file = num_term; 11997 *num_file = num_term;
11999 else 11998 else
12000 return OK; 11999 return OK;
12001 *file = (char_u **)alloc(*num_file * sizeof(char_u *)); 12000 *file = ALLOC_MULT(char_u *, *num_file);
12002 if (*file == NULL) 12001 if (*file == NULL)
12003 { 12002 {
12004 *file = (char_u **)""; 12003 *file = (char_u **)"";
12005 return FAIL; 12004 return FAIL;
12006 } 12005 }
12014 { 12013 {
12015 char_u *var = NULL; /* init for GCC */ 12014 char_u *var = NULL; /* init for GCC */
12016 char_u *buf; 12015 char_u *buf;
12017 12016
12018 *num_file = 0; 12017 *num_file = 0;
12019 *file = (char_u **)alloc(sizeof(char_u *)); 12018 *file = ALLOC_ONE(char_u *);
12020 if (*file == NULL) 12019 if (*file == NULL)
12021 return FAIL; 12020 return FAIL;
12022 12021
12023 /* 12022 /*
12024 * For a terminal key code expand_option_idx is < 0. 12023 * For a terminal key code expand_option_idx is < 0.
12877 } 12876 }
12878 emsg(_(e_invarg)); 12877 emsg(_(e_invarg));
12879 return FALSE; 12878 return FALSE;
12880 } 12879 }
12881 12880
12882 *array = (int *)alloc((valcount + 1) * sizeof(int)); 12881 *array = ALLOC_MULT(int, valcount + 1);
12883 if (*array == NULL) 12882 if (*array == NULL)
12884 return FALSE; 12883 return FALSE;
12885 (*array)[0] = valcount; 12884 (*array)[0] = valcount;
12886 12885
12887 t = 1; 12886 t = 1;
13100 int *newts; 13099 int *newts;
13101 int t; 13100 int t;
13102 13101
13103 if (oldts == NULL) 13102 if (oldts == NULL)
13104 return NULL; 13103 return NULL;
13105 newts = (int *)alloc((oldts[0] + 1) * sizeof(int)); 13104 newts = ALLOC_MULT(int, oldts[0] + 1);
13106 if (newts != NULL) 13105 if (newts != NULL)
13107 for (t = 0; t <= oldts[0]; ++t) 13106 for (t = 0; t <= oldts[0]; ++t)
13108 newts[t] = oldts[t]; 13107 newts[t] = oldts[t];
13109 return newts; 13108 return newts;
13110 } 13109 }