Skip to content

Commit 960dcbd

Browse files
yegappanbrammool
authored andcommitted
patch 9.0.1391: "clear" macros are not always used
Problem: "clear" macros are not always used. Solution: Use ALLOC_ONE, VIM_CLEAR, CLEAR_POINTER and CLEAR_FIELD in more places. (Yegappan Lakshmanan, closes #12104)
1 parent 14113fd commit 960dcbd

23 files changed

+39
-70
lines changed

src/buffer.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2375,8 +2375,7 @@ free_buf_options(
23752375
clear_string_option(&buf->b_p_isk);
23762376
#ifdef FEAT_VARTABS
23772377
clear_string_option(&buf->b_p_vsts);
2378-
vim_free(buf->b_p_vsts_nopaste);
2379-
buf->b_p_vsts_nopaste = NULL;
2378+
VIM_CLEAR(buf->b_p_vsts_nopaste);
23802379
VIM_CLEAR(buf->b_p_vsts_array);
23812380
clear_string_option(&buf->b_p_vts);
23822381
VIM_CLEAR(buf->b_p_vts_array);

src/channel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ fd_write(sock_T fd, char *buf, size_t len)
109109
size = (DWORD)todo;
110110
// If the pipe overflows while the job does not read the data,
111111
// WriteFile() will block forever. This abandons the write.
112-
memset(&ov, 0, sizeof(ov));
112+
CLEAR_FIELD(ov);
113113
nwrite = 0;
114114
if (!WriteFile(h, buf + done, size, &nwrite, &ov))
115115
{

src/debugger.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,12 @@ do_debug(char_u *cmd)
9797
if (debug_oldval != NULL)
9898
{
9999
smsg(_("Oldval = \"%s\""), debug_oldval);
100-
vim_free(debug_oldval);
101-
debug_oldval = NULL;
100+
VIM_CLEAR(debug_oldval);
102101
}
103102
if (debug_newval != NULL)
104103
{
105104
smsg(_("Newval = \"%s\""), debug_newval);
106-
vim_free(debug_newval);
107-
debug_newval = NULL;
105+
VIM_CLEAR(debug_newval);
108106
}
109107
sname = estack_sfile(ESTACK_NONE);
110108
if (sname != NULL)

src/diff.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -726,10 +726,7 @@ diff_redraw(
726726
clear_diffin(diffin_T *din)
727727
{
728728
if (din->din_fname == NULL)
729-
{
730-
vim_free(din->din_mmfile.ptr);
731-
din->din_mmfile.ptr = NULL;
732-
}
729+
VIM_CLEAR(din->din_mmfile.ptr);
733730
else
734731
mch_remove(din->din_fname);
735732
}

src/evalfunc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4354,7 +4354,7 @@ f_expandcmd(typval_T *argvars, typval_T *rettv)
43544354
rettv->v_type = VAR_STRING;
43554355
cmdstr = vim_strsave(tv_get_string(&argvars[0]));
43564356

4357-
memset(&eap, 0, sizeof(eap));
4357+
CLEAR_FIELD(eap);
43584358
eap.cmd = cmdstr;
43594359
eap.arg = cmdstr;
43604360
eap.argt |= EX_NOSPC;

src/fileio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4382,7 +4382,7 @@ buf_reload(buf_T *buf, int orig_mode, int reload_options)
43824382
// file, not reset the syntax highlighting, clear marks, diff status, etc.
43834383
// Force the fileformat and encoding to be the same.
43844384
if (reload_options)
4385-
memset(&ea, 0, sizeof(ea));
4385+
CLEAR_FIELD(ea);
43864386
else
43874387
prepped = prep_exarg(&ea, buf);
43884388

src/gui_photon.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,7 @@ gui_mch_browse(
14001400
char_u *open_text = NULL;
14011401

14021402
flags = 0;
1403-
memset(&file, 0, sizeof(file));
1403+
CLEAR_FIELD(file);
14041404

14051405
default_path = alloc(MAXPATHL + 1 + NAME_MAX + 1);
14061406
if (default_path != NULL)
@@ -1578,8 +1578,8 @@ gui_mch_dialog(
15781578
PtModalCtrl_t modal_ctrl;
15791579
PtDialogInfo_t di;
15801580

1581-
memset(&di, 0, sizeof(di));
1582-
memset(&modal_ctrl, 0, sizeof(modal_ctrl));
1581+
CLEAR_FIELD(di);
1582+
CLEAR_FIELD(modal_ctrl);
15831583

15841584
n = 0;
15851585
PtSetArg(&args[n++], Pt_ARG_GROUP_ROWS_COLS, 0, 0);
@@ -1707,7 +1707,7 @@ gui_mch_iconify(void)
17071707
{
17081708
PhWindowEvent_t event;
17091709

1710-
memset(&event, 0, sizeof (event));
1710+
CLEAR_FIELD(event);
17111711
event.event_f = Ph_WM_HIDE;
17121712
event.event_state = Ph_WM_EVSTATE_HIDE;
17131713
event.rid = PtWidgetRid(gui.vimWindow);
@@ -1723,7 +1723,7 @@ gui_mch_set_foreground(void)
17231723
{
17241724
PhWindowEvent_t event;
17251725

1726-
memset(&event, 0, sizeof (event));
1726+
CLEAR_FIELD(event);
17271727
event.event_f = Ph_WM_TOFRONT;
17281728
event.event_state = Ph_WM_EVSTATE_FFRONT;
17291729
event.rid = PtWidgetRid(gui.vimWindow);

src/gui_w32.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8387,7 +8387,7 @@ make_tooltip(BalloonEval *beval, char *text, POINT pt)
83878387
TOOLINFOW *pti;
83888388
RECT rect;
83898389

8390-
pti = alloc(sizeof(TOOLINFOW));
8390+
pti = ALLOC_ONE(TOOLINFOW);
83918391
if (pti == NULL)
83928392
return;
83938393

@@ -8655,7 +8655,7 @@ netbeans_draw_multisign_indicator(int row)
86558655

86568656
// TODO: at the moment, this is just a copy of test_gui_mouse_event.
86578657
// But, we could instead generate actual Win32 mouse event messages,
8658-
// ie. to make it consistent wih test_gui_w32_sendevent_keyboard.
8658+
// ie. to make it consistent with test_gui_w32_sendevent_keyboard.
86598659
static int
86608660
test_gui_w32_sendevent_mouse(dict_T *args)
86618661
{

src/hardcopy.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2721,14 +2721,10 @@ mch_print_begin(prt_settings_T *psettings)
27212721
struct prt_ps_resource_S *res_cmap;
27222722
int retval = FALSE;
27232723

2724-
res_prolog = (struct prt_ps_resource_S *)
2725-
alloc(sizeof(struct prt_ps_resource_S));
2726-
res_encoding = (struct prt_ps_resource_S *)
2727-
alloc(sizeof(struct prt_ps_resource_S));
2728-
res_cidfont = (struct prt_ps_resource_S *)
2729-
alloc(sizeof(struct prt_ps_resource_S));
2730-
res_cmap = (struct prt_ps_resource_S *)
2731-
alloc(sizeof(struct prt_ps_resource_S));
2724+
res_prolog = ALLOC_ONE(struct prt_ps_resource_S);
2725+
res_encoding = ALLOC_ONE(struct prt_ps_resource_S);
2726+
res_cidfont = ALLOC_ONE(struct prt_ps_resource_S);
2727+
res_cmap = ALLOC_ONE(struct prt_ps_resource_S);
27322728
if (res_prolog == NULL || res_encoding == NULL
27332729
|| res_cidfont == NULL || res_cmap == NULL)
27342730
goto theend;

src/indent.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ tabstop_set(char_u *var, int **array)
7474
if (n <= 0 || n > TABSTOP_MAX)
7575
{
7676
semsg(_(e_invalid_argument_str), cp);
77-
vim_free(*array);
78-
*array = NULL;
77+
VIM_CLEAR(*array);
7978
return FAIL;
8079
}
8180
(*array)[t++] = n;

0 commit comments

Comments
 (0)