Mercurial > vim
comparison src/eval.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 | 5f98d80d116a |
children | a836d122231a |
comparison
equal
deleted
inserted
replaced
16824:1f6bb29738d2 | 16825:ce04ebdf26b8 |
---|---|
489 /* Make a copy of the name, it is used in redir_lval until redir ends. */ | 489 /* Make a copy of the name, it is used in redir_lval until redir ends. */ |
490 redir_varname = vim_strsave(name); | 490 redir_varname = vim_strsave(name); |
491 if (redir_varname == NULL) | 491 if (redir_varname == NULL) |
492 return FAIL; | 492 return FAIL; |
493 | 493 |
494 redir_lval = (lval_T *)alloc_clear(sizeof(lval_T)); | 494 redir_lval = ALLOC_CLEAR_ONE(lval_T); |
495 if (redir_lval == NULL) | 495 if (redir_lval == NULL) |
496 { | 496 { |
497 var_redir_stop(); | 497 var_redir_stop(); |
498 return FAIL; | 498 return FAIL; |
499 } | 499 } |
1061 typval_T * | 1061 typval_T * |
1062 eval_expr(char_u *arg, char_u **nextcmd) | 1062 eval_expr(char_u *arg, char_u **nextcmd) |
1063 { | 1063 { |
1064 typval_T *tv; | 1064 typval_T *tv; |
1065 | 1065 |
1066 tv = (typval_T *)alloc(sizeof(typval_T)); | 1066 tv = ALLOC_ONE(typval_T); |
1067 if (tv != NULL && eval0(arg, tv, nextcmd, TRUE) == FAIL) | 1067 if (tv != NULL && eval0(arg, tv, nextcmd, TRUE) == FAIL) |
1068 VIM_CLEAR(tv); | 1068 VIM_CLEAR(tv); |
1069 | 1069 |
1070 return tv; | 1070 return tv; |
1071 } | 1071 } |
2767 typval_T tv; | 2767 typval_T tv; |
2768 list_T *l; | 2768 list_T *l; |
2769 | 2769 |
2770 *errp = TRUE; /* default: there is an error */ | 2770 *errp = TRUE; /* default: there is an error */ |
2771 | 2771 |
2772 fi = (forinfo_T *)alloc_clear(sizeof(forinfo_T)); | 2772 fi = ALLOC_CLEAR_ONE(forinfo_T); |
2773 if (fi == NULL) | 2773 if (fi == NULL) |
2774 return NULL; | 2774 return NULL; |
2775 | 2775 |
2776 expr = skip_var_list(arg, &fi->fi_varcount, &fi->fi_semicolon); | 2776 expr = skip_var_list(arg, &fi->fi_varcount, &fi->fi_semicolon); |
2777 if (expr == NULL) | 2777 if (expr == NULL) |
7295 * value). | 7295 * value). |
7296 */ | 7296 */ |
7297 typval_T * | 7297 typval_T * |
7298 alloc_tv(void) | 7298 alloc_tv(void) |
7299 { | 7299 { |
7300 return (typval_T *)alloc_clear(sizeof(typval_T)); | 7300 return ALLOC_CLEAR_ONE(typval_T); |
7301 } | 7301 } |
7302 | 7302 |
7303 /* | 7303 /* |
7304 * Allocate memory for a variable type-value, and assign a string to it. | 7304 * Allocate memory for a variable type-value, and assign a string to it. |
7305 * The string "s" must have been allocated, it is consumed. | 7305 * The string "s" must have been allocated, it is consumed. |
7881 } | 7881 } |
7882 | 7882 |
7883 while (ga_scripts.ga_len < id) | 7883 while (ga_scripts.ga_len < id) |
7884 { | 7884 { |
7885 sv = SCRIPT_SV(ga_scripts.ga_len + 1) = | 7885 sv = SCRIPT_SV(ga_scripts.ga_len + 1) = |
7886 (scriptvar_T *)alloc_clear(sizeof(scriptvar_T)); | 7886 ALLOC_CLEAR_ONE(scriptvar_T); |
7887 init_var_dict(&sv->sv_dict, &sv->sv_var, VAR_SCOPE); | 7887 init_var_dict(&sv->sv_dict, &sv->sv_var, VAR_SCOPE); |
7888 ++ga_scripts.ga_len; | 7888 ++ga_scripts.ga_len; |
7889 } | 7889 } |
7890 } | 7890 } |
7891 } | 7891 } |
8137 | 8137 |
8138 // Make sure the variable name is valid. | 8138 // Make sure the variable name is valid. |
8139 if (!valid_varname(varname)) | 8139 if (!valid_varname(varname)) |
8140 return; | 8140 return; |
8141 | 8141 |
8142 v = (dictitem_T *)alloc(sizeof(dictitem_T) + STRLEN(varname)); | 8142 v = alloc(sizeof(dictitem_T) + STRLEN(varname)); |
8143 if (v == NULL) | 8143 if (v == NULL) |
8144 return; | 8144 return; |
8145 STRCPY(v->di_key, varname); | 8145 STRCPY(v->di_key, varname); |
8146 if (hash_add(ht, DI2HIKEY(v)) == FAIL) | 8146 if (hash_add(ht, DI2HIKEY(v)) == FAIL) |
8147 { | 8147 { |