0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

patch 8.0.1481: clearing a pointer takes two lines

Problem:    Clearing a pointer takes two lines.
Solution:   Add vim_clear() to free and clear the pointer.
This commit is contained in:
Bram Moolenaar
2018-02-09 12:29:56 +01:00
parent 0562532c2e
commit 1567558b20
4 changed files with 30 additions and 25 deletions

View File

@@ -2927,8 +2927,7 @@ ins_compl_del_pum(void)
if (compl_match_array != NULL) if (compl_match_array != NULL)
{ {
pum_undisplay(); pum_undisplay();
vim_free(compl_match_array); vim_clear((void **)&compl_match_array);
compl_match_array = NULL;
} }
} }
@@ -3430,10 +3429,8 @@ ins_compl_free(void)
compl_T *match; compl_T *match;
int i; int i;
vim_free(compl_pattern); vim_clear((void **)&compl_pattern);
compl_pattern = NULL; vim_clear((void **)&compl_leader);
vim_free(compl_leader);
compl_leader = NULL;
if (compl_first_match == NULL) if (compl_first_match == NULL)
return; return;
@@ -3465,13 +3462,10 @@ ins_compl_clear(void)
compl_cont_status = 0; compl_cont_status = 0;
compl_started = FALSE; compl_started = FALSE;
compl_matches = 0; compl_matches = 0;
vim_free(compl_pattern); vim_clear((void **)&compl_pattern);
compl_pattern = NULL; vim_clear((void **)&compl_leader);
vim_free(compl_leader);
compl_leader = NULL;
edit_submode_extra = NULL; edit_submode_extra = NULL;
vim_free(compl_orig_text); vim_clear((void **)&compl_orig_text);
compl_orig_text = NULL;
compl_enter_selects = FALSE; compl_enter_selects = FALSE;
/* clear v:completed_item */ /* clear v:completed_item */
set_vim_var_dict(VV_COMPLETED_ITEM, dict_alloc_lock(VAR_FIXED)); set_vim_var_dict(VV_COMPLETED_ITEM, dict_alloc_lock(VAR_FIXED));
@@ -5574,10 +5568,8 @@ ins_complete(int c, int enable_pum)
if (compl_orig_text == NULL || ins_compl_add(compl_orig_text, if (compl_orig_text == NULL || ins_compl_add(compl_orig_text,
-1, p_ic, NULL, NULL, 0, ORIGINAL_TEXT, FALSE) != OK) -1, p_ic, NULL, NULL, 0, ORIGINAL_TEXT, FALSE) != OK)
{ {
vim_free(compl_pattern); vim_clear((void **)&compl_pattern);
compl_pattern = NULL; vim_clear((void **)&compl_orig_text);
vim_free(compl_orig_text);
compl_orig_text = NULL;
return FAIL; return FAIL;
} }
@@ -7206,11 +7198,9 @@ set_last_insert(int c)
void void
free_last_insert(void) free_last_insert(void)
{ {
vim_free(last_insert); vim_clear((void **)&last_insert);
last_insert = NULL;
# ifdef FEAT_INS_EXPAND # ifdef FEAT_INS_EXPAND
vim_free(compl_orig_text); vim_clear((void **)&compl_orig_text);
compl_orig_text = NULL;
# endif # endif
} }
#endif #endif
@@ -7838,8 +7828,7 @@ mb_replace_pop_ins(int cc)
static void static void
replace_flush(void) replace_flush(void)
{ {
vim_free(replace_stack); vim_clear((void **)&replace_stack);
replace_stack = NULL;
replace_stack_len = 0; replace_stack_len = 0;
replace_stack_nr = 0; replace_stack_nr = 0;
} }

View File

@@ -1836,6 +1836,19 @@ vim_free(void *x)
} }
} }
/*
* Like vim_free(), and also set the pointer to NULL.
*/
void
vim_clear(void **x)
{
if (*x != NULL)
{
vim_free(*x);
*x = NULL;
}
}
#ifndef HAVE_MEMSET #ifndef HAVE_MEMSET
void * void *
vim_memset(void *ptr, int c, size_t size) vim_memset(void *ptr, int c, size_t size)
@@ -5173,8 +5186,8 @@ ff_wc_equal(char_u *s1, char_u *s2)
prev2 = prev1; prev2 = prev1;
prev1 = c1; prev1 = c1;
i += MB_PTR2LEN(s1 + i); i += MB_PTR2LEN(s1 + i);
j += MB_PTR2LEN(s2 + j); j += MB_PTR2LEN(s2 + j);
} }
return s1[i] == s2[j]; return s1[i] == s2[j];
} }
@@ -5892,7 +5905,7 @@ pathcmp(const char *p, const char *q, int maxlen)
if (c2 == NUL) /* full match */ if (c2 == NUL) /* full match */
return 0; return 0;
s = q; s = q;
i = j; i = j;
break; break;
} }

View File

@@ -46,6 +46,7 @@ void vim_strncpy(char_u *to, char_u *from, size_t len);
void vim_strcat(char_u *to, char_u *from, size_t tosize); void vim_strcat(char_u *to, char_u *from, size_t tosize);
int copy_option_part(char_u **option, char_u *buf, int maxlen, char *sep_chars); int copy_option_part(char_u **option, char_u *buf, int maxlen, char *sep_chars);
void vim_free(void *x); void vim_free(void *x);
void vim_clear(void **x);
int vim_stricmp(char *s1, char *s2); int vim_stricmp(char *s1, char *s2);
int vim_strnicmp(char *s1, char *s2, size_t len); int vim_strnicmp(char *s1, char *s2, size_t len);
char_u *vim_strchr(char_u *string, int c); char_u *vim_strchr(char_u *string, int c);

View File

@@ -771,6 +771,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1481,
/**/ /**/
1480, 1480,
/**/ /**/