Skip to content

Commit 1567558

Browse files
committed
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.
1 parent 0562532 commit 1567558

4 files changed

Lines changed: 30 additions & 25 deletions

File tree

src/edit.c

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2927,8 +2927,7 @@ ins_compl_del_pum(void)
29272927
if (compl_match_array != NULL)
29282928
{
29292929
pum_undisplay();
2930-
vim_free(compl_match_array);
2931-
compl_match_array = NULL;
2930+
vim_clear((void **)&compl_match_array);
29322931
}
29332932
}
29342933

@@ -3430,10 +3429,8 @@ ins_compl_free(void)
34303429
compl_T *match;
34313430
int i;
34323431

3433-
vim_free(compl_pattern);
3434-
compl_pattern = NULL;
3435-
vim_free(compl_leader);
3436-
compl_leader = NULL;
3432+
vim_clear((void **)&compl_pattern);
3433+
vim_clear((void **)&compl_leader);
34373434

34383435
if (compl_first_match == NULL)
34393436
return;
@@ -3465,13 +3462,10 @@ ins_compl_clear(void)
34653462
compl_cont_status = 0;
34663463
compl_started = FALSE;
34673464
compl_matches = 0;
3468-
vim_free(compl_pattern);
3469-
compl_pattern = NULL;
3470-
vim_free(compl_leader);
3471-
compl_leader = NULL;
3465+
vim_clear((void **)&compl_pattern);
3466+
vim_clear((void **)&compl_leader);
34723467
edit_submode_extra = NULL;
3473-
vim_free(compl_orig_text);
3474-
compl_orig_text = NULL;
3468+
vim_clear((void **)&compl_orig_text);
34753469
compl_enter_selects = FALSE;
34763470
/* clear v:completed_item */
34773471
set_vim_var_dict(VV_COMPLETED_ITEM, dict_alloc_lock(VAR_FIXED));
@@ -5574,10 +5568,8 @@ ins_complete(int c, int enable_pum)
55745568
if (compl_orig_text == NULL || ins_compl_add(compl_orig_text,
55755569
-1, p_ic, NULL, NULL, 0, ORIGINAL_TEXT, FALSE) != OK)
55765570
{
5577-
vim_free(compl_pattern);
5578-
compl_pattern = NULL;
5579-
vim_free(compl_orig_text);
5580-
compl_orig_text = NULL;
5571+
vim_clear((void **)&compl_pattern);
5572+
vim_clear((void **)&compl_orig_text);
55815573
return FAIL;
55825574
}
55835575

@@ -7206,11 +7198,9 @@ set_last_insert(int c)
72067198
void
72077199
free_last_insert(void)
72087200
{
7209-
vim_free(last_insert);
7210-
last_insert = NULL;
7201+
vim_clear((void **)&last_insert);
72117202
# ifdef FEAT_INS_EXPAND
7212-
vim_free(compl_orig_text);
7213-
compl_orig_text = NULL;
7203+
vim_clear((void **)&compl_orig_text);
72147204
# endif
72157205
}
72167206
#endif
@@ -7838,8 +7828,7 @@ mb_replace_pop_ins(int cc)
78387828
static void
78397829
replace_flush(void)
78407830
{
7841-
vim_free(replace_stack);
7842-
replace_stack = NULL;
7831+
vim_clear((void **)&replace_stack);
78437832
replace_stack_len = 0;
78447833
replace_stack_nr = 0;
78457834
}

src/misc2.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,6 +1836,19 @@ vim_free(void *x)
18361836
}
18371837
}
18381838

1839+
/*
1840+
* Like vim_free(), and also set the pointer to NULL.
1841+
*/
1842+
void
1843+
vim_clear(void **x)
1844+
{
1845+
if (*x != NULL)
1846+
{
1847+
vim_free(*x);
1848+
*x = NULL;
1849+
}
1850+
}
1851+
18391852
#ifndef HAVE_MEMSET
18401853
void *
18411854
vim_memset(void *ptr, int c, size_t size)
@@ -5173,8 +5186,8 @@ ff_wc_equal(char_u *s1, char_u *s2)
51735186
prev2 = prev1;
51745187
prev1 = c1;
51755188

5176-
i += MB_PTR2LEN(s1 + i);
5177-
j += MB_PTR2LEN(s2 + j);
5189+
i += MB_PTR2LEN(s1 + i);
5190+
j += MB_PTR2LEN(s2 + j);
51785191
}
51795192
return s1[i] == s2[j];
51805193
}
@@ -5892,7 +5905,7 @@ pathcmp(const char *p, const char *q, int maxlen)
58925905
if (c2 == NUL) /* full match */
58935906
return 0;
58945907
s = q;
5895-
i = j;
5908+
i = j;
58965909
break;
58975910
}
58985911

src/proto/misc2.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ void vim_strncpy(char_u *to, char_u *from, size_t len);
4646
void vim_strcat(char_u *to, char_u *from, size_t tosize);
4747
int copy_option_part(char_u **option, char_u *buf, int maxlen, char *sep_chars);
4848
void vim_free(void *x);
49+
void vim_clear(void **x);
4950
int vim_stricmp(char *s1, char *s2);
5051
int vim_strnicmp(char *s1, char *s2, size_t len);
5152
char_u *vim_strchr(char_u *string, int c);

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,8 @@ static char *(features[]) =
771771

772772
static int included_patches[] =
773773
{ /* Add new patch number below this line */
774+
/**/
775+
1481,
774776
/**/
775777
1480,
776778
/**/

0 commit comments

Comments
 (0)