diff options
author | Bram Moolenaar <Bram@vim.org> | 2018-02-10 18:45:26 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2018-02-10 18:45:26 +0100 |
commit | d23a823669d93fb2a570a039173eefe4856ac806 (patch) | |
tree | 617130258eae70e3bd7ef7b6da9c494ffee7b572 /src | |
parent | 42443c7d7fecc3a2a72154bb6139b028438617c2 (diff) | |
download | vim-git-d23a823669d93fb2a570a039173eefe4856ac806.tar.gz |
patch 8.0.1496: clearing a pointer takes two linesv8.0.1496
Problem: Clearing a pointer takes two lines.
Solution: Add VIM_CLEAR() and replace vim_clear(). (Hirohito Higashi,
closes #2629)
Diffstat (limited to 'src')
54 files changed, 234 insertions, 466 deletions
diff --git a/src/buffer.c b/src/buffer.c index c0d3d3d9f..c3e0c5080 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -944,8 +944,7 @@ free_buffer_stuff( map_clear_int(buf, MAP_ALL_MODES, TRUE, TRUE); /* clear local abbrevs */ #endif #ifdef FEAT_MBYTE - vim_free(buf->b_start_fenc); - buf->b_start_fenc = NULL; + VIM_CLEAR(buf->b_start_fenc); #endif } @@ -2037,10 +2036,8 @@ buflist_new( if ((ffname != NULL && (buf->b_ffname == NULL || buf->b_sfname == NULL)) || buf->b_wininfo == NULL) { - vim_free(buf->b_ffname); - buf->b_ffname = NULL; - vim_free(buf->b_sfname); - buf->b_sfname = NULL; + VIM_CLEAR(buf->b_ffname); + VIM_CLEAR(buf->b_sfname); if (buf != curbuf) free_buffer(buf); return NULL; @@ -3136,10 +3133,8 @@ setfname( if (ffname == NULL || *ffname == NUL) { /* Removing the name. */ - vim_free(buf->b_ffname); - vim_free(buf->b_sfname); - buf->b_ffname = NULL; - buf->b_sfname = NULL; + VIM_CLEAR(buf->b_ffname); + VIM_CLEAR(buf->b_sfname); #ifdef UNIX st.st_dev = (dev_T)-1; #endif @@ -4261,8 +4256,7 @@ build_stl_str_hl( if (*skipdigits(str) == NUL) { num = atoi((char *)str); - vim_free(str); - str = NULL; + VIM_CLEAR(str); itemisflag = FALSE; } } diff --git a/src/channel.c b/src/channel.c index 138b12ece..77df42dd9 100644 --- a/src/channel.c +++ b/src/channel.c @@ -317,8 +317,8 @@ channel_still_useful(channel_T *channel) /* If there is no callback then nobody can get readahead. If the fd is * closed and there is no readahead then the callback won't be called. */ has_sock_msg = channel->ch_part[PART_SOCK].ch_fd != INVALID_FD - || channel->ch_part[PART_SOCK].ch_head.rq_next != NULL - || channel->ch_part[PART_SOCK].ch_json_head.jq_next != NULL; + || channel->ch_part[PART_SOCK].ch_head.rq_next != NULL + || channel->ch_part[PART_SOCK].ch_json_head.jq_next != NULL; has_out_msg = channel->ch_part[PART_OUT].ch_fd != INVALID_FD || channel->ch_part[PART_OUT].ch_head.rq_next != NULL || channel->ch_part[PART_OUT].ch_json_head.jq_next != NULL; @@ -2978,8 +2978,7 @@ channel_clear_one(channel_T *channel, ch_part_T part) channel_clear(channel_T *channel) { ch_log(channel, "Clearing channel"); - vim_free(channel->ch_hostname); - channel->ch_hostname = NULL; + VIM_CLEAR(channel->ch_hostname); channel_clear_one(channel, PART_SOCK); channel_clear_one(channel, PART_OUT); channel_clear_one(channel, PART_ERR); diff --git a/src/crypt.c b/src/crypt.c index 81759069f..dfbf02ca5 100644 --- a/src/crypt.c +++ b/src/crypt.c @@ -118,6 +118,9 @@ static cryptmethod_T cryptmethods[CRYPT_M_COUNT] = { NULL, NULL, crypt_blowfish_encode, crypt_blowfish_decode, }, + + /* NOTE: when adding a new method, use some random bytes for the magic key, + * to avoid that a text file is recognized as encrypted. */ }; #define CRYPT_MAGIC_LEN 12 /* cannot change */ @@ -349,10 +352,7 @@ crypt_create_for_writing( state = crypt_create(method_nr, key, salt, salt_len, seed, seed_len); if (state == NULL) - { - vim_free(*header); - *header = NULL; - } + VIM_CLEAR(*header); return state; } diff --git a/src/edit.c b/src/edit.c index 7074f2648..f0e5c5185 100644 --- a/src/edit.c +++ b/src/edit.c @@ -2939,7 +2939,7 @@ ins_compl_del_pum(void) if (compl_match_array != NULL) { pum_undisplay(); - vim_clear((void **)&compl_match_array); + VIM_CLEAR(compl_match_array); } } @@ -3441,8 +3441,8 @@ ins_compl_free(void) compl_T *match; int i; - vim_clear((void **)&compl_pattern); - vim_clear((void **)&compl_leader); + VIM_CLEAR(compl_pattern); + VIM_CLEAR(compl_leader); if (compl_first_match == NULL) return; @@ -3474,10 +3474,10 @@ ins_compl_clear(void) compl_cont_status = 0; compl_started = FALSE; compl_matches = 0; - vim_clear((void **)&compl_pattern); - vim_clear((void **)&compl_leader); + VIM_CLEAR(compl_pattern); + VIM_CLEAR(compl_leader); edit_submode_extra = NULL; - vim_clear((void **)&compl_orig_text); + VIM_CLEAR(compl_orig_text); compl_enter_selects = FALSE; /* clear v:completed_item */ set_vim_var_dict(VV_COMPLETED_ITEM, dict_alloc_lock(VAR_FIXED)); @@ -5584,8 +5584,8 @@ ins_complete(int c, int enable_pum) if (compl_orig_text == NULL || ins_compl_add(compl_orig_text, -1, p_ic, NULL, NULL, 0, ORIGINAL_TEXT, FALSE) != OK) { - vim_clear((void **)&compl_pattern); - vim_clear((void **)&compl_orig_text); + VIM_CLEAR(compl_pattern); + VIM_CLEAR(compl_orig_text); return FAIL; } @@ -7214,9 +7214,9 @@ set_last_insert(int c) void free_last_insert(void) { - vim_clear((void **)&last_insert); + VIM_CLEAR(last_insert); # ifdef FEAT_INS_EXPAND - vim_clear((void **)&compl_orig_text); + VIM_CLEAR(compl_orig_text); # endif } #endif @@ -7844,7 +7844,7 @@ mb_replace_pop_ins(int cc) static void replace_flush(void) { - vim_clear((void **)&replace_stack); + VIM_CLEAR(replace_stack); replace_stack_len = 0; replace_stack_nr = 0; } diff --git a/src/eval.c b/src/eval.c index 85f607cb7..f20fdda13 100644 --- a/src/eval.c +++ b/src/eval.c @@ -361,10 +361,7 @@ eval_clear(void) { p = &vimvars[i]; if (p->vv_di.di_tv.v_type == VAR_STRING) - { - vim_free(p->vv_str); - p->vv_str = NULL; - } + VIM_CLEAR(p->vv_str); else if (p->vv_di.di_tv.v_type == VAR_LIST) { list_unref(p->vv_list); @@ -569,14 +566,11 @@ var_redir_stop(void) } /* free the collected output */ - vim_free(redir_ga.ga_data); - redir_ga.ga_data = NULL; + VIM_CLEAR(redir_ga.ga_data); - vim_free(redir_lval); - redir_lval = NULL; + VIM_CLEAR(redir_lval); } - vim_free(redir_varname); - redir_varname = NULL; + VIM_CLEAR(redir_varname); } # if defined(FEAT_MBYTE) || defined(PROTO) @@ -1009,10 +1003,7 @@ eval_expr(char_u *arg, char_u **nextcmd) tv = (typval_T *)alloc(sizeof(typval_T)); if (tv != NULL && eval0(arg, tv, nextcmd, TRUE) == FAIL) - { - vim_free(tv); - tv = NULL; - } + VIM_CLEAR(tv); return tv; } @@ -3213,8 +3204,7 @@ get_user_var_name(expand_T *xp, int idx) if (vidx < VV_LEN) return cat_prefix_varname('v', (char_u *)vimvars[vidx++].vv_name); - vim_free(varnamebuf); - varnamebuf = NULL; + VIM_CLEAR(varnamebuf); varnamebuflen = 0; return NULL; } @@ -6096,10 +6086,7 @@ get_env_tv(char_u **arg, typval_T *rettv, int evaluate) /* next try expanding things like $VIM and ${HOME} */ string = expand_env_save(name - 1); if (string != NULL && *string == '$') - { - vim_free(string); - string = NULL; - } + VIM_CLEAR(string); } name[len] = cc; @@ -7116,8 +7103,7 @@ clear_tv(typval_T *varp) func_unref(varp->vval.v_string); /* FALLTHROUGH */ case VAR_STRING: - vim_free(varp->vval.v_string); - varp->vval.v_string = NULL; + VIM_CLEAR(varp->vval.v_string); break; case VAR_PARTIAL: partial_unref(varp->vval.v_partial); diff --git a/src/evalfunc.c b/src/evalfunc.c index 4b34538b7..f09be92af 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -9222,10 +9222,7 @@ f_resolve(typval_T *argvars, typval_T *rettv) if (*q != NUL) STRMOVE(remain, q - 1); else - { - vim_free(remain); - remain = NULL; - } + VIM_CLEAR(remain); } /* If the result is a relative path name, make it explicitly relative to diff --git a/src/ex_cmds.c b/src/ex_cmds.c index f4129019a..11dac0620 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -1957,8 +1957,7 @@ write_viminfo(char_u *file, int forceit) if (!shortname && st_new.st_dev == st_old.st_dev && st_new.st_ino == st_old.st_ino) { - vim_free(tempname); - tempname = NULL; + VIM_CLEAR(tempname); shortname = TRUE; break; } @@ -5225,8 +5224,7 @@ do_sub(exarg_T *eap) lnum += regmatch.startpos[0].lnum; sub_firstlnum += regmatch.startpos[0].lnum; nmatch -= regmatch.startpos[0].lnum; - vim_free(sub_firstline); - sub_firstline = NULL; + VIM_CLEAR(sub_firstline); } if (sub_firstline == NULL) @@ -5388,10 +5386,7 @@ do_sub(exarg_T *eap) sub_firstline + copycol); if (new_line == NULL) - { - vim_free(orig_line); - orig_line = NULL; - } + VIM_CLEAR(orig_line); else { /* Position the cursor relative to the @@ -5820,8 +5815,7 @@ skip: if (did_sub) ++sub_nlines; vim_free(new_start); /* for when substitute was cancelled */ - vim_free(sub_firstline); /* free the copy of the original line */ - sub_firstline = NULL; + VIM_CLEAR(sub_firstline); /* free the copy of the original line */ } line_breakcheck(); @@ -6975,8 +6969,7 @@ fix_help_buffer(void) && fnamecmp(e1, fname + 4) != 0) { /* Not .txt and not .abx, remove it. */ - vim_free(fnames[i1]); - fnames[i1] = NULL; + VIM_CLEAR(fnames[i1]); continue; } if (e1 - f1 != e2 - f2 @@ -6984,11 +6977,8 @@ fix_help_buffer(void) continue; if (fnamecmp(e1, ".txt") == 0 && fnamecmp(e2, fname + 4) == 0) - { /* use .abx instead of .txt */ - vim_free(fnames[i1]); - fnames[i1] = NULL; - } + VIM_CLEAR(fnames[i1]); } } #endif diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c index 73fe0194b..6caed87bb 100644 --- a/src/ex_cmds2.c +++ b/src/ex_cmds2.c @@ -1298,7 +1298,6 @@ check_due_timer(void) if (this_due <= 1) { bevalexpr_due_set = FALSE; - if (balloonEval == NULL) { balloonEval = (BalloonEval *)alloc(sizeof(BalloonEval)); @@ -5489,8 +5488,7 @@ free_locales(void) { for (i = 0; locales[i] != NULL; i++) vim_free(locales[i]); - vim_free(locales); - locales = NULL; + VIM_CLEAR(locales); } } # endif diff --git a/src/ex_docmd.c b/src/ex_docmd.c index 591775f4c..408263676 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -868,8 +868,7 @@ do_cmdline( { /* Each '|' separated command is stored separately in lines_ga, to * be able to jump to it. Don't use next_cmdline now. */ - vim_free(cmdline_copy); - cmdline_copy = NULL; + VIM_CLEAR(cmdline_copy); /* Check if a function has returned or, unless it has an unclosed * try conditional, aborted. */ @@ -1084,8 +1083,7 @@ do_cmdline( if (next_cmdline == NULL) { - vim_free(cmdline_copy); - cmdline_copy = NULL; + VIM_CLEAR(cmdline_copy); #ifdef FEAT_CMDHIST /* * If the command was typed, remember it for the ':' register. @@ -5802,11 +5800,9 @@ uc_add_command( goto fail; } - vim_free(cmd->uc_rep); - cmd->uc_rep = NULL; + VIM_CLEAR(cmd->uc_rep); #if defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL) - vim_free(cmd->uc_compl_arg); - cmd->uc_compl_arg = NULL; + VIM_CLEAR(cmd->uc_compl_arg); #endif break; } @@ -8952,11 +8948,8 @@ static char_u *prev_dir = NULL; void free_cd_dir(void) { - vim_free(prev_dir); - prev_dir = NULL; - - vim_free(globaldir); - globaldir = NULL; + VIM_CLEAR(prev_dir); + VIM_CLEAR(globaldir); } #endif @@ -8967,8 +8960,7 @@ free_cd_dir(void) void post_chdir(int local) { - vim_free(curwin->w_localdir); - curwin->w_localdir = NULL; + VIM_CLEAR(curwin->w_localdir); if (local) { /* If still in global directory, need to remember current @@ -8983,8 +8975,7 @@ post_chdir(int local) { /* We are now in the global directory, no need to remember its * name. */ - vim_free(globaldir); - globaldir = NULL; + VIM_CLEAR(globaldir); } shorten_fnames(TRUE); diff --git a/src/ex_getln.c b/src/ex_getln.c index 837d29998..a9d6bd483 100644 --- a/src/ex_getln.c +++ b/src/ex_getln.c @@ -164,8 +164,7 @@ trigger_cmd_autocmd(int typechar, int evt) static void abandon_cmdline(void) { - vim_free(ccline.cmdbuff); - ccline.cmdbuff = NULL; + VIM_CLEAR(ccline.cmdbuff); if (msg_scrolled == 0) compute_cmdrow(); MSG(""); @@ -500,10 +499,7 @@ getcmdline( && c != K_KPAGEDOWN && c != K_KPAGEUP && c != K_LEFT && c != K_RIGHT && (xpc.xp_numfiles > 0 || (c != Ctrl_P && c != Ctrl_N))) - { - vim_free(lookfor); - lookfor = NULL; - } + VIM_CLEAR(lookfor); #endif /* @@ -1096,8 +1092,7 @@ getcmdline( ) goto cmdline_not_changed; - vim_free(ccline.cmdbuff); /* no commandline to return */ - ccline.cmdbuff = NULL; + VIM_CLEAR(ccline.cmdbuff); /* no commandline to return */ if (!cmd_silent) { #ifdef FEAT_RIGHTLEFT @@ -3683,10 +3678,7 @@ nextwild( || ccline.cmdbuff[i + j] == '?') break; if ((int)STRLEN(p2) < j) - { - vim_free(p2); - p2 = NULL; - } + VIM_CLEAR(p2); } } } @@ -3832,8 +3824,7 @@ ExpandOne( { FreeWild(xp->xp_numfiles, xp->xp_files); xp->xp_numfiles = -1; - vim_free(orig_save); - orig_save = NULL; + VIM_CLEAR(orig_save); } findex = 0; @@ -6737,8 +6728,7 @@ finish_viminfo_history(vir_T *virp) else concat_history(type); - vim_free(viminfo_history[type]); - viminfo_history[type] = NULL; + VIM_CLEAR(viminfo_history[type]); viminfo_hisidx[type] = 0; } } @@ -6862,8 +6852,7 @@ write_viminfo_history(FILE *fp, int merge) for (i = 0; i < viminfo_hisidx[type]; ++i) if (viminfo_history[type] != NULL) vim_free(viminfo_history[type][i].hisstr); - vim_free(viminfo_history[type]); - viminfo_history[type] = NULL; + VIM_CLEAR(viminfo_history[type]); viminfo_hisidx[type] = 0; } } diff --git a/src/fileio.c b/src/fileio.c index d4735f344..8798cff1b 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -1073,8 +1073,7 @@ retry: if (tmpname != NULL) { mch_remove(tmpname); /* delete converted file */ - vim_free(tmpname); - tmpname = NULL; + VIM_CLEAR(tmpname); } } @@ -2602,8 +2601,7 @@ failed: #endif msg_add_lines(c, (long)linecnt, filesize); - vim_free(keep_msg); - keep_msg = NULL; + VIM_CLEAR(keep_msg); msg_scrolled_ign = TRUE; #ifdef ALWAYS_USE_GUI /* Don't show the message when reading stdin, it would end up in a @@ -2955,8 +2953,7 @@ readfile_charconvert( if (tmpname != NULL) { mch_remove(tmpname); /* delete converted file */ - vim_free(tmpname); - tmpname = NULL; + VIM_CLEAR(tmpname); } } @@ -3945,8 +3942,7 @@ buf_write( if (st_new.st_dev == st_old.st_dev && st_new.st_ino == st_old.st_ino) { - vim_free(backup); - backup = NULL; /* no backup file to delete */ + VIM_CLEAR(backup); /* no backup file to delete */ /* * may try again with 'shortname' set */ @@ -3980,10 +3976,7 @@ buf_write( --*wp; /* They all exist??? Must be something wrong. */ if (*wp == 'a') - { - vim_free(backup); - backup = NULL; - } + VIM_CLEAR(backup); } } break; @@ -4010,10 +4003,7 @@ buf_write( (void)umask(umask_save); #endif if (bfd < 0) - { - vim_free(backup); - backup = NULL; - } + VIM_CLEAR(backup); else { /* Set file protection same as original file, but @@ -4156,10 +4146,7 @@ buf_write( --*p; /* They all exist??? Must be something wrong! */ if (*p == 'a') - { - vim_free(backup); - backup = NULL; - } + VIM_CLEAR(backup); } } if (backup != NULL) @@ -4177,8 +4164,7 @@ buf_write( if (vim_rename(fname, backup) == 0) break; - vim_free(backup); /* don't do the rename below */ - backup = NULL; + VIM_CLEAR(backup); /* don't do the rename below */ } } if (backup == NULL && !forceit) @@ -5079,8 +5065,7 @@ restore_backup: else if (mch_stat(org, &st) < 0) { vim_rename(backup, (char_u *)org); - vim_free(backup); /* don't delete the file */ - backup = NULL; + VIM_CLEAR(backup); /* don't delete the file */ #ifdef UNIX set_file_time((char_u *)org, st_old.st_atime, st_old.st_mtime); #endif @@ -6227,8 +6212,7 @@ shorten_fnames(int force) || buf->b_sfname == NULL || mch_isFullName(buf->b_sfname))) { - vim_free(buf->b_sfname); - buf->b_sfname = NULL; + VIM_CLEAR(buf->b_sfname); p = shorten_fname(buf->b_ffname, dirname); if (p != NULL) { @@ -7427,8 +7411,7 @@ vim_deltempdir(void) /* remove the trailing path separator */ gettail(vim_tempdir)[-1] = NUL; delete_recursive(vim_tempdir); - vim_free(vim_tempdir); - vim_tempdir = NULL; + VIM_CLEAR(vim_tempdir); } } @@ -8018,8 +8001,7 @@ show_autocmd(AutoPat *ap, event_T event) static void au_remove_pat(AutoPat *ap) { - vim_free(ap->pat); - ap->pat = NULL; + VIM_CLEAR(ap->pat); ap->buflocal_nr = -1; au_need_clean = TRUE; } @@ -8033,10 +8015,7 @@ au_remove_cmds(AutoPat *ap) AutoCmd *ac; for (ac = ap->cmds; ac != NULL; ac = ac->next) - { - vim_free(ac->cmd); - ac->cmd = NULL; - } + VIM_CLEAR(ac->cmd); au_need_clean = TRUE; } @@ -9094,8 +9073,7 @@ aucmd_prepbuf( /* Make sure w_localdir and globaldir are NULL to avoid a chdir() in * win_enter_ext(). */ - vim_free(aucmd_win->w_localdir); - aucmd_win->w_localdir = NULL; + VIM_CLEAR(aucmd_win->w_localdir); aco->globaldir = globaldir; globaldir = NULL; @@ -9877,8 +9855,7 @@ auto_next_pat( char_u *name; char *s; - vim_free(sourcing_name); - sourcing_name = NULL; + VIM_CLEAR(sourcing_name); for (ap = apc->curpat; ap != NULL && !got_int; ap = ap->next) { @@ -10561,8 +10538,7 @@ file_pat_to_reg_pat( EMSG(_("E219: Missing {.")); else EMSG(_("E220: Missing }.")); - vim_free(reg_pat); - reg_pat = NULL; + VIM_CLEAR(reg_pat); } return reg_pat; } diff --git a/src/gui_gtk_x11.c b/src/gui_gtk_x11.c index ad51be62c..2f88c2eeb 100644 --- a/src/gui_gtk_x11.c +++ b/src/gui_gtk_x11.c @@ -3838,8 +3838,7 @@ gui_mch_init(void) # endif } #endif - vim_free(gui_argv); - gui_argv = NULL; + VIM_CLEAR(gui_argv); #if GLIB_CHECK_VERSION(2,1,3) /* Set the human-readable application name */ @@ -4668,8 +4667,7 @@ gui_mch_open(void) y += hh - pixel_height; gtk_window_move(GTK_WINDOW(gui.mainwin), x, y); } - vim_free(gui.geom); - gui.geom = NULL; + VIM_CLEAR(gui.geom); /* From now until everyone's stopped trying to set the window hints * to their correct minimum values, stop them being set as we need diff --git a/src/gui_photon.c b/src/gui_photon.c index fcfb4f6d9..327b35651 100644 --- a/src/gui_photon.c +++ b/src/gui_photon.c @@ -1040,8 +1040,7 @@ gui_ph_pg_remove_buffer(char *name) PtSetResource(gui.vimPanelGroup, Pt_ARG_PG_PANEL_TITLES, &empty_title, 1); - vim_free(panel_titles); - panel_titles = NULL; + VIM_CLEAR(panel_titles); } } diff --git a/src/gui_w32.c b/src/gui_w32.c index 67aa1fc11..6596cf81e 100644 --- a/src/gui_w32.c +++ b/src/gui_w32.c @@ -4941,8 +4941,7 @@ _WndProc( char_u *str = NULL; static void *tt_text = NULL; - vim_free(tt_text); - tt_text = NULL; + VIM_CLEAR(tt_text); # ifdef FEAT_GUI_TABLINE if (gui_mch_showing_tabline() diff --git a/src/gui_x11.c b/src/gui_x11.c index 34d584e78..097de5f90 100644 --- a/src/gui_x11.c +++ b/src/gui_x11.c @@ -826,7 +826,7 @@ gui_x11_key_hit_cb( # endif ) { - int maxlen = len * 4 + 40; /* guessed */ + int maxlen = len * 4 + 40; /* guessed */ char_u *p = (char_u *)XtMalloc(maxlen); mch_memmove(p, string, len); @@ -1567,8 +1567,7 @@ gui_mch_uninit(void) XtCloseDisplay(gui.dpy); gui.dpy = NULL; vimShell = (Widget)0; - vim_free(gui_argv); - gui_argv = NULL; + VIM_CLEAR(gui_argv); } /* @@ -1741,8 +1740,7 @@ gui_mch_exit(int rc UNUSED) * says that this isn't needed when exiting, so just skip it. */ XtCloseDisplay(gui.dpy); #endif - vim_free(gui_argv); - gui_argv = NULL; + VIM_CLEAR(gui_argv); } /* @@ -1956,7 +1954,7 @@ gui_mch_get_font(char_u *name, int giveErrorIfMissing) { XFontStruct *font; - if (!gui.in_use || name == NULL) /* can't do this when GUI not running */ + if (!gui.in_use || name == NULL) /* can't do this when GUI not running */ return NOFONT; font = XLoadQueryFont(gui.dpy, (char *)name); @@ -2275,7 +2273,7 @@ fontset_ascent(XFontSet fs) guicolor_T gui_mch_get_color(char_u *name) { - guicolor_T requested; + guicolor_T requested; /* can't do this when GUI not running */ if (!gui.in_use || name == NULL || *name == NUL) @@ -2298,8 +2296,8 @@ gui_mch_get_color(char_u *name) guicolor_T gui_mch_get_rgb_color(int r, int g, int b) { - char spec[8]; /* space enough to hold "#RRGGBB" */ - XColor available; + char spec[8]; /* space enough to hold "#RRGGBB" */ + XColor available; Colormap colormap; vim_snprintf(spec, sizeof(spec), "#%.2x%.2x%.2x", r, g, b); diff --git a/src/hardcopy.c b/src/hardcopy.c index 4a0910d8c..96fab2048 100644 --- a/src/hardcopy.c +++ b/src/hardcopy.c @@ -2210,8 +2210,7 @@ mch_print_cleanup(void) for (i = PRT_PS_FONT_ROMAN; i <= PRT_PS_FONT_BOLDOBLIQUE; i++) { if (prt_ps_mb_font.ps_fontname[i] != NULL) - vim_free(prt_ps_mb_font.ps_fontname[i]); - prt_ps_mb_font.ps_fontname[i] = NULL; + VIM_CLEAR(prt_ps_mb_font.ps_fontname[i]); } } @@ -2228,10 +2227,7 @@ mch_print_cleanup(void) prt_file_error = FALSE; } if (prt_ps_file_name != NULL) - { - vim_free(prt_ps_file_name); - prt_ps_file_name = NULL; - } + VIM_CLEAR(prt_ps_file_name); } static float diff --git a/src/if_cscope.c b/src/if_cscope.c index 4bf28ad1d..e4bcb51e0 100644 --- a/src/if_cscope.c +++ b/src/if_cscope.c @@ -1479,8 +1479,7 @@ cs_insert_filelist( { if ((csinfo[i].ppath = (char *)alloc((unsigned)strlen(ppath) + 1)) == NULL) { - vim_free(csinfo[i].fname); - csinfo[i].fname = NULL; + VIM_CLEAR(csinfo[i].fname); return -1; } (void)strcpy(csinfo[i].ppath, (const char *)ppath); @@ -1491,10 +1490,8 @@ cs_insert_filelist( { if ((csinfo[i].flags = (char *)alloc((unsigned)strlen(flags) + 1)) == NULL) { - vim_free(csinfo[i].fname); - vim_free(csinfo[i].ppath); - csinfo[i].fname = NULL; - csinfo[i].ppath = NULL; + VIM_CLEAR(csinfo[i].fname); + VIM_CLEAR(csinfo[i].ppath); return -1; } (void)strcpy(csinfo[i].flags, (const char *)flags); @@ -1939,10 +1936,8 @@ parse_out: if (totsofar == 0) { /* No matches, free the arrays and return NULL in "*matches_p". */ - vim_free(matches); - matches = NULL; - vim_free(cntxts); - cntxts = NULL; + VIM_CLEAR(matches); + VIM_CLEAR(cntxts); } *matched = totsofar; *matches_p = matches; @@ -2445,7 +2440,7 @@ cs_resolve_file(int i, char *name) if (csdir != NULL) { vim_strncpy(csdir, (char_u *)csinfo[i].fname, - gettail((char_u *)csinfo[i].fname) + gettail((char_u *)csinfo[i].fname) - (char_u *)csinfo[i].fname); len += (int)STRLEN(csdir); } diff --git a/src/macros.h b/src/macros.h index 6e4b813c0..43d6c94cf 100644 --- a/src/macros.h +++ b/src/macros.h @@ -379,3 +379,14 @@ # define mch_enable_flush() # define mch_disable_flush() #endif + +/* + * Like vim_free(), and also set the pointer to NULL. + */ +#define VIM_CLEAR(p) \ + do { \ + if ((p) != NULL) { \ + vim_free(p); \ + (p) = NULL; \ + } \ + } while (0) diff --git a/src/main.c b/src/main.c index 971590aab..78a30182e 100644 --- a/src/main.c +++ b/src/main.c @@ -3951,8 +3951,7 @@ cmdsrv_main( { /* Output error from remote */ mch_errmsg((char *)res); - vim_free(res); - res = NULL; + VIM_CLEAR(res); } mch_errmsg(_(": Send expression failed.\n")); } diff --git a/src/mark.c b/src/mark.c index 342bfcd9f..1acdd12d6 100644 --- a/src/mark.c +++ b/src/mark.c @@ -127,8 +127,7 @@ setmark_pos(int c, pos_T *pos, int fnum) i = c - 'A'; namedfm[i].fmark.mark = *pos; namedfm[i].fmark.fnum = fnum; - vim_free(namedfm[i].fname); - namedfm[i].fname = NULL; + VIM_CLEAR(namedfm[i].fname); #ifdef FEAT_VIMINFO namedfm[i].time_set = vim_time(); #endif @@ -598,8 +597,7 @@ fmarks_check_one(xfmark_T *fm, char_u *name, buf_T *buf) && fnamecmp(name, fm->fname) == 0) { fm->fmark.fnum = buf->b_fnum; - vim_free(fm->fname); - fm->fname = NULL; + VIM_CLEAR(fm->fname); } } @@ -862,8 +860,7 @@ ex_delmarks(exarg_T *eap) else n = i - 'A'; namedfm[n].fmark.mark.lnum = 0; - vim_free(namedfm[n].fname); - namedfm[n].fname = NULL; + VIM_CLEAR(namedfm[n].fname); #ifdef FEAT_VIMINFO namedfm[n].time_set = 0; #endif @@ -1480,16 +1477,14 @@ finish_viminfo_marks(void) { for (i = 0; i < NMARKS + EXTRA_MARKS; ++i) vim_free(vi_namedfm[i].fname); - vim_free(vi_namedfm); - vi_namedfm = NULL; + VIM_CLEAR(vi_namedfm); } #ifdef FEAT_JUMPLIST if (vi_jumplist != NULL) { for (i = 0; i < vi_jumplist_len; ++i) vim_free(vi_jumplist[i].fname); - vim_free(vi_jumplist); - vi_jumplist = NULL; + VIM_CLEAR(vi_jumplist); } #endif } diff --git a/src/mbyte.c b/src/mbyte.c index 5ed321ed2..575fd52d4 100644 --- a/src/mbyte.c +++ b/src/mbyte.c @@ -4666,8 +4666,7 @@ iconv_string( else if (ICONV_ERRNO != ICONV_E2BIG) { /* conversion failed */ - vim_free(result); - result = NULL; + VIM_CLEAR(result); break; } /* Not enough room or skipping illegal sequence. */ diff --git a/src/memfile.c b/src/memfile.c index 0fb27871b..0d07b7558 100644 --- a/src/memfile.c +++ b/src/memfile.c @@ -297,10 +297,8 @@ mf_close_file( if (mfp->mf_fname != NULL) { mch_remove(mfp->mf_fname); /* delete the swap file */ - vim_free(mfp->mf_fname); - vim_free(mfp->mf_ffname); - mfp->mf_fname = NULL; - mfp->mf_ffname = NULL; + VIM_CLEAR(mfp->mf_fname); + VIM_CLEAR(mfp->mf_ffname); } } @@ -1288,10 +1286,8 @@ mf_do_open( */ if (mfp->mf_fd < 0) { - vim_free(mfp->mf_fname); - vim_free(mfp->mf_ffname); - mfp->mf_fname = NULL; - mfp->mf_ffname = NULL; + VIM_CLEAR(mfp->mf_fname); + VIM_CLEAR(mfp->mf_ffname); } else { diff --git a/src/memline.c b/src/memline.c index 07721ee1a..7ea94ab8b 100644 --- a/src/memline.c +++ b/src/memline.c @@ -535,8 +535,7 @@ ml_set_crypt_key( idx = 0; /* start with first index in block 1 */ error = 0; buf->b_ml.ml_stack_top = 0; - vim_free(buf->b_ml.ml_stack); - buf->b_ml.ml_stack = NULL; + VIM_CLEAR(buf->b_ml.ml_stack); buf->b_ml.ml_stack_size = 0; /* no stack yet */ for ( ; !got_int; line_breakcheck()) @@ -852,8 +851,7 @@ ml_close(buf_T *buf, int del_file) vim_free(buf->b_ml.ml_line_ptr); vim_free(buf->b_ml.ml_stack); #ifdef FEAT_BYTEOFF - vim_free(buf->b_ml.ml_chunksize); - buf->b_ml.ml_chunksize = NULL; + VIM_CLEAR(buf->b_ml.ml_chunksize); #endif buf->b_ml.ml_mfp = NULL; @@ -4197,8 +4195,7 @@ findswapname( break; if ((n = (int)STRLEN(fname)) == 0) /* safety check */ { - vim_free(fname); - fname = NULL; + VIM_CLEAR(fname); break; } #if defined(UNIX) @@ -4578,8 +4575,7 @@ findswapname( if (fname[n - 2] == 'a') /* ".saa": tried enough, give up */ { EMSG(_("E326: Too many swap files found")); - vim_free(fname); - fname = NULL; + VIM_CLEAR(fname); break; } --fname[n - 2]; /* ".svz", ".suz", etc. */ diff --git a/src/menu.c b/src/menu.c index 3728aa779..310cf5928 100644 --- a/src/menu.c +++ b/src/menu.c @@ -727,8 +727,7 @@ add_menu_path( menup = &menu->children; parent = menu; name = next_name; - vim_free(dname); - dname = NULL; + VIM_CLEAR(dname); if (pri_tab[pri_idx + 1] != -1) ++pri_idx; } diff --git a/src/message.c b/src/message.c index 17a663352..71965852f 100644 --- a/src/message.c +++ b/src/message.c @@ -415,8 +415,7 @@ static char_u *last_sourcing_name = NULL; void reset_last_sourcing(void) { - vim_free(last_sourcing_name); - last_sourcing_name = NULL; + VIM_CLEAR(last_sourcing_name); last_sourcing_lnum = 0; } @@ -1249,10 +1248,7 @@ wait_return(int redraw) reset_last_sourcing(); if (keep_msg != NULL && vim_strsize(keep_msg) >= (Rows - cmdline_row - 1) * Columns + sc_col) - { - vim_free(keep_msg); - keep_msg = NULL; /* don't redisplay message, it's too long */ - } + VIM_CLEAR(keep_msg); /* don't redisplay message, it's too long */ if (tmpState == SETWSIZE) /* got resize event while in vgetc() */ { @@ -1325,10 +1321,7 @@ msg_start(void) int did_return = FALSE; if (!msg_silent) - { - vim_free(keep_msg); - keep_msg = NULL; /* don't display old message now */ - } + VIM_CLEAR(keep_msg); #ifdef FEAT_EVAL if (need_clr_eos) @@ -3481,8 +3474,7 @@ give_warning(char_u *message, int hl) #ifdef FEAT_EVAL set_vim_var_string(VV_WARNINGMSG, message, -1); #endif - vim_free(keep_msg); - keep_msg = NULL; + VIM_CLEAR(keep_msg); if (hl) keep_msg_attr = HL_ATTR(HLF_W); else diff --git a/src/misc1.c b/src/misc1.c index 593dce1c3..821869aa3 100644 --- a/src/misc1.c +++ b/src/misc1.c @@ -3745,8 +3745,7 @@ init_homedir(void) char_u *var; /* In case we are called a second time (when 'encoding' changes). */ - vim_free(homedir); - homedir = NULL; + VIM_CLEAR(homedir); #ifdef VMS var = mch_getenv((char_u *)"SYS$LOGIN"); @@ -4358,10 +4357,7 @@ vim_getenv(char_u *name, int *mustfree) p = vim_strnsave(p, (int)(pend - p)); if (p != NULL && !mch_isdir(p)) - { - vim_free(p); - p = NULL; - } + VIM_CLEAR(p); else { #ifdef USE_EXE_NAME @@ -9775,8 +9771,7 @@ expand_wildcards( /* If the number of matches is now zero, we fail. */ if (*num_files == 0) { - vim_free(*files); - *files = NULL; + VIM_CLEAR(*files); return FAIL; } } @@ -10031,10 +10026,7 @@ dos_expandpath( hFind = FindFirstFileW(wn, &wfb); if (hFind == INVALID_HANDLE_VALUE && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) - { - vim_free(wn); - wn = NULL; - } + VIM_CLEAR(wn); } } @@ -10122,8 +10114,7 @@ dos_expandpath( # endif hFind = FindFirstFile((LPCSTR)buf, &fb); ok = (hFind != INVALID_HANDLE_VALUE); - vim_free(matchname); - matchname = NULL; + VIM_CLEAR(matchname); } } @@ -11256,8 +11247,7 @@ get_cmd_output( if (i != len) { EMSG2(_(e_notread), tempname); - vim_free(buffer); - buffer = NULL; + VIM_CLEAR(buffer); } else if (ret_len == NULL) { diff --git a/src/misc2.c b/src/misc2.c index 0deccdf50..1c705932d 100644 --- a/src/misc2.c +++ b/src/misc2.c @@ -1827,6 +1827,8 @@ copy_option_part( * Replacement for free() that ignores NULL pointers. * Also skip free() when exiting for sure, this helps when we caught a deadly * signal that was caused by a crash in free(). + * If you want to set NULL after calling this function, you should use + * VIM_CLEAR() instead. */ void vim_free(void *x) @@ -1840,19 +1842,6 @@ 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 void * vim_memset(void *ptr, int c, size_t size) diff --git a/src/netbeans.c b/src/netbeans.c index 199cfd63c..bc3b8e680 100644 --- a/src/netbeans.c +++ b/src/netbeans.c @@ -580,8 +580,7 @@ nb_free(void) buf.bufp->b_was_netbeans_file = FALSE; } } - vim_free(buf_list); - buf_list = NULL; + VIM_CLEAR(buf_list); buf_list_size = 0; buf_list_used = 0; @@ -1477,8 +1476,7 @@ nb_do_cmd( EMSG("E636: invalid buffer identifier in create"); return FAIL; } - vim_free(buf->displayname); - buf->displayname = NULL; + VIM_CLEAR(buf->displayname); netbeansReadFile = 0; /* don't try to open disk file */ do_ecmd(0, NULL, 0, 0, ECMD_ONE, ECMD_HIDE + ECMD_OLDBUF, curwin); @@ -3447,8 +3445,7 @@ print_read_msg(nbbuf_T *buf) msg_add_lines(c, (long)lnum, nchars); /* Now display it */ - vim_free(keep_msg); - keep_msg = NULL; + VIM_CLEAR(keep_msg); msg_scrolled_ign = TRUE; msg_trunc_attr(IObuff, FALSE, 0); msg_scrolled_ign = FALSE; @@ -3475,8 +3472,7 @@ print_save_msg(nbbuf_T *buf, off_T nchars) msg_add_lines(c, buf->bufp->b_ml.ml_line_count, buf->bufp->b_orig_size); - vim_free(keep_msg); - keep_msg = NULL; + VIM_CLEAR(keep_msg); msg_scrolled_ign = TRUE; p = msg_trunc_attr(IObuff, FALSE, 0); if ((msg_scrolled && !need_wait_return) || !buf->initDone) diff --git a/src/normal.c b/src/normal.c index 79e0b68aa..31ec36306 100644 --- a/src/normal.c +++ b/src/normal.c @@ -1482,8 +1482,7 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank) { AppendToRedobuffLit(repeat_cmdline, -1); AppendToRedobuff(NL_STR); - vim_free(repeat_cmdline); - repeat_cmdline = NULL; + VIM_CLEAR(repeat_cmdline); } } } @@ -1235,8 +1235,7 @@ do_execreg( EMSG(_(e_nolastcmd)); return FAIL; } - vim_free(new_last_cmdline); /* don't keep the cmdline containing @: */ - new_last_cmdline = NULL; + VIM_CLEAR(new_last_cmdline); /* don't keep the cmdline containing @: */ /* Escape all control characters with a CTRL-V */ p = vim_strsave_escaped_ext(last_cmdline, (char_u *)"\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037", Ctrl_V, FALSE); @@ -2995,8 +2994,7 @@ free_yank(long n) #endif vim_free(y_current->y_array[i]); } - vim_free(y_current->y_array); - y_current->y_array = NULL; + VIM_CLEAR(y_current->y_array); #ifdef AMIGA if (n >= 1000) MSG(""); @@ -6040,8 +6038,7 @@ finish_viminfo_registers(void) vim_free(y_read_regs[i].y_array[j]); vim_free(y_read_regs[i].y_array); } - vim_free(y_read_regs); - y_read_regs = NULL; + VIM_CLEAR(y_read_regs); } } @@ -7146,8 +7143,7 @@ str_to_reg( /* Without any lines make the register empty. */ if (y_ptr->y_size + newlines == 0) { - vim_free(y_ptr->y_array); - y_ptr->y_array = NULL; + VIM_CLEAR(y_ptr->y_array); return; } diff --git a/src/option.c b/src/option.c index e54ba4e2d..21ca0fa48 100644 --- a/src/option.c +++ b/src/option.c @@ -11735,8 +11735,7 @@ ExpandOldSetting(int *num_file, char_u ***file) if (buf == NULL) { - vim_free(*file); - *file = NULL; + VIM_CLEAR(*file); return FAIL; } diff --git a/src/os_amiga.c b/src/os_amiga.c index 85e0c4ef0..a0fb5c084 100644 --- a/src/os_amiga.c +++ b/src/os_amiga.c @@ -1619,8 +1619,7 @@ mch_getenv(char_u *var) else #endif { - vim_free(alloced); - alloced = NULL; + VIM_CLEAR(alloced); retval = NULL; buf = alloc(IOSIZE); diff --git a/src/os_mac_conv.c b/src/os_mac_conv.c index 1fddc61f3..2bd337ea6 100644 --- a/src/os_mac_conv.c +++ b/src/os_mac_conv.c @@ -480,10 +480,7 @@ mac_precompose_path( if (TECConvertText(gPathConverter, decompPath, decompLen, &decompLen, result, decompLen, &actualLen) != noErr) - { - vim_free(result); - result = NULL; - } + VIM_CLEAR(result); } } @@ -517,10 +514,7 @@ mac_utf16_to_utf8( utf8_len += inputRead; } else - { - vim_free(result); - result = NULL; - } + VIM_CLEAR(result); } else { diff --git a/src/os_mswin.c b/src/os_mswin.c index ef756421f..a41b4c82b 100644 --- a/src/os_mswin.c +++ b/src/os_mswin.c @@ -1233,8 +1233,7 @@ PrintDlgProc( if (prt_name != NULL) { vimSetDlgItemText(hDlg, IDC_PRINTTEXT2, (char_u *)prt_name); - vim_free(prt_name); - prt_name = NULL; + VIM_CLEAR(prt_name); } EnableMenuItem(GetSystemMenu(hDlg, FALSE), SC_CLOSE, MF_GRAYED); #ifndef FEAT_GUI @@ -2608,6 +2607,7 @@ serverGetReply(HWND server, int *expr_res, int remove, int wait, int timeout) while (reply_received == 0) { #ifdef FEAT_TIMERS + /* TODO: use the return value to decide how long to wait. */ check_due_timer(); #endif time(&now); diff --git a/src/os_unix.c b/src/os_unix.c index ff0b0e88d..3788da991 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -371,7 +371,7 @@ mch_chdir(char *path) #endif /* - * Write s[len] to the screen. + * Write s[len] to the screen (stdout). */ void mch_write(char_u *s, int len) @@ -1311,8 +1311,7 @@ mch_suspend(void) /* * Set oldtitle to NULL, so the current title is obtained again. */ - vim_free(oldtitle); - oldtitle = NULL; + VIM_CLEAR(oldtitle); # endif settmode(TMODE_RAW); need_check_timestamps = TRUE; @@ -3261,8 +3260,7 @@ mch_free_mem(void) XCloseDisplay(x11_display); # endif # if defined(HAVE_SIGALTSTACK) || defined(HAVE_SIGSTACK) - vim_free(signal_stack); - signal_stack = NULL; + VIM_CLEAR(signal_stack); # endif # ifdef FEAT_TITLE vim_free(oldtitle); @@ -6765,8 +6763,7 @@ mch_expand_wildcards( if (*num_file == 0) /* rejected all entries */ { - vim_free(*file); - *file = NULL; + VIM_CLEAR(*file); goto notfound; } diff --git a/src/os_win32.c b/src/os_win32.c index a42df6f29..121ff2aa1 100644 --- a/src/os_win32.c +++ b/src/os_win32.c @@ -2252,8 +2252,7 @@ SaveConsoleBuffer( cb->Regions = (PSMALL_RECT)alloc(cb->NumRegions * sizeof(SMALL_RECT)); if (cb->Regions == NULL) { - vim_free(cb->Buffer); - cb->Buffer = NULL; + VIM_CLEAR(cb->Buffer); return FALSE; } } @@ -2278,10 +2277,8 @@ SaveConsoleBuffer( BufferCoord, /* offset in our buffer */ &ReadRegion)) /* region to save */ { - vim_free(cb->Buffer); - cb->Buffer = NULL; - vim_free(cb->Regions); - cb->Regions = NULL; + VIM_CLEAR(cb->Buffer); + VIM_CLEAR(cb->Regions); return FALSE; } cb->Regions[i] = ReadRegion; diff --git a/src/popupmnu.c b/src/popupmnu.c index 09d9520a6..2839ea199 100644 --- a/src/popupmnu.c +++ b/src/popupmnu.c @@ -975,8 +975,7 @@ ui_remove_balloon(void) pum_undisplay(); while (balloon_arraysize > 0) vim_free(balloon_array[--balloon_arraysize].pum_text); - vim_free(balloon_array); - balloon_array = NULL; + VIM_CLEAR(balloon_array); } } diff --git a/src/proto/misc2.pro b/src/proto/misc2.pro index 4c20a7c0f..6999683c7 100644 --- a/src/proto/misc2.pro +++ b/src/proto/misc2.pro @@ -46,7 +46,6 @@ void vim_strncpy(char_u *to, char_u *from, size_t len); 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); void vim_free(void *x); -void vim_clear(void **x); int vim_stricmp(char *s1, char *s2); int vim_strnicmp(char *s1, char *s2, size_t len); char_u *vim_strchr(char_u *string, int c); diff --git a/src/quickfix.c b/src/quickfix.c index b2dabaaac..c3b28e4ec 100644 --- a/src/quickfix.c +++ b/src/quickfix.c @@ -1177,8 +1177,7 @@ qf_init_ext( int status; /* Do not used the cached buffer, it may have been wiped out. */ - vim_free(qf_last_bufname); - qf_last_bufname = NULL; + VIM_CLEAR(qf_last_bufname); vim_memset(&state, 0, sizeof(state)); vim_memset(&fields, 0, sizeof(fields)); @@ -1229,8 +1228,7 @@ qf_init_ext( if (last_efm == NULL || (STRCMP(last_efm, efm) != 0)) { /* free the previously parsed data */ - vim_free(last_efm); - last_efm = NULL; + VIM_CLEAR(last_efm); free_efm_list(&fmt_first); /* parse the current 'efm' */ @@ -1351,8 +1349,7 @@ qf_init_end: static void qf_store_title(qf_info_T *qi, int qf_idx, char_u *title) { - vim_free(qi->qf_lists[qf_idx].qf_title); - qi->qf_lists[qf_idx].qf_title = NULL; + VIM_CLEAR(qi->qf_lists[qf_idx].qf_title); if (title != NULL) { @@ -3003,8 +3000,7 @@ qf_free(qf_info_T *qi, int idx) qf_free_items(qi, idx); - vim_free(qfl->qf_title); - qfl->qf_title = NULL; + VIM_CLEAR(qfl->qf_title); free_tv(qfl->qf_ctx); qfl->qf_ctx = NULL; qfl->qf_id = 0; diff --git a/src/regexp.c b/src/regexp.c index 7f5e265eb..d07391eef 100644 --- a/src/regexp.c +++ b/src/regexp.c @@ -3996,10 +3996,7 @@ theend: /* Free "reg_tofree" when it's a bit big. * Free regstack and backpos if they are bigger than their initial size. */ if (reg_tofreelen > 400) - { - vim_free(reg_tofree); - reg_tofree = NULL; - } + VIM_CLEAR(reg_tofree); if (regstack.ga_maxlen > REGSTACK_INITIAL) ga_clear(®stack); if (backpos.ga_maxlen > BACKPOS_INITIAL) @@ -7521,8 +7518,7 @@ vim_regsub_both( { STRCPY(dest, eval_result); dst += STRLEN(eval_result); - vim_free(eval_result); - eval_result = NULL; + VIM_CLEAR(eval_result); } } else @@ -8150,7 +8146,7 @@ vim_regcomp(char_u *expr_arg, int re_flags) * First try the NFA engine, unless backtracking was requested. */ if (regexp_engine != BACKTRACKING_ENGINE) - prog = nfa_regengine.regcomp(expr, + prog = nfa_regengine.regcomp(expr, re_flags + (regexp_engine == AUTOMATIC_ENGINE ? RE_AUTO : 0)); else prog = bt_regengine.regcomp(expr, re_flags); @@ -8170,7 +8166,7 @@ vim_regcomp(char_u *expr_arg, int re_flags) } else EMSG2("(NFA) Could not open \"%s\" to write !!!", - BT_REGEXP_DEBUG_LOG_NAME); + BT_REGEXP_DEBUG_LOG_NAME); } #endif /* @@ -8341,10 +8337,10 @@ vim_regexec_nl(regmatch_T *rmp, char_u *line, colnr_T col) long vim_regexec_multi( regmmatch_T *rmp, - win_T *win, /* window in which to search or NULL */ - buf_T *buf, /* buffer in which to search */ - linenr_T lnum, /* nr of line to start looking for match */ - colnr_T col, /* column to start looking for match */ + win_T *win, /* window in which to search or NULL */ + buf_T *buf, /* buffer in which to search */ + linenr_T lnum, /* nr of line to start looking for match */ + colnr_T col, /* column to start looking for match */ proftime_T *tm, /* timeout limit or NULL */ int *timed_out) /* flag is set when timeout limit reached */ { diff --git a/src/regexp_nfa.c b/src/regexp_nfa.c index 70003a05b..90fff64b5 100644 --- a/src/regexp_nfa.c +++ b/src/regexp_nfa.c @@ -7334,14 +7334,13 @@ nfa_regcomp(char_u *expr, int re_flags) nfa_regengine.expr = NULL; out: - vim_free(post_start); - post_start = post_ptr = post_end = NULL; + VIM_CLEAR(post_start); + post_ptr = post_end = NULL; state_ptr = NULL; return (regprog_T *)prog; fail: - vim_free(prog); - prog = NULL; + VIM_CLEAR(prog); #ifdef ENABLE_LOG nfa_postfix_dump(expr, FAIL); #endif diff --git a/src/screen.c b/src/screen.c index f365be223..ce9b6e98e 100644 --- a/src/screen.c +++ b/src/screen.c @@ -4326,10 +4326,7 @@ win_line( #endif if (p_extra_free != NULL) - { - vim_free(p_extra_free); - p_extra_free = NULL; - } + VIM_CLEAR(p_extra_free); /* * Get a character from the line itself. */ @@ -8860,27 +8857,17 @@ give_up: * and over again. */ done_outofmem_msg = TRUE; } - vim_free(new_ScreenLines); - new_ScreenLines = NULL; + VIM_CLEAR(new_ScreenLines); #ifdef FEAT_MBYTE - vim_free(new_ScreenLinesUC); - new_ScreenLinesUC = NULL; + VIM_CLEAR(new_ScreenLinesUC); for (i = 0; i < p_mco; ++i) - { - vim_free(new_ScreenLinesC[i]); - new_ScreenLinesC[i] = NULL; - } - vim_free(new_ScreenLines2); - new_ScreenLines2 = NULL; + VIM_CLEAR(new_ScreenLinesC[i]); + VIM_CLEAR(new_ScreenLines2); #endif - vim_free(new_ScreenAttrs); - new_ScreenAttrs = NULL; - vim_free(new_LineOffset); - new_LineOffset = NULL; - vim_free(new_LineWraps); - new_LineWraps = NULL; - vim_free(new_TabPageIdxs); - new_TabPageIdxs = NULL; + VIM_CLEAR(new_ScreenAttrs); + VIM_CLEAR(new_LineOffset); + VIM_CLEAR(new_LineWraps); + VIM_CLEAR(new_TabPageIdxs); } else { diff --git a/src/search.c b/src/search.c index 7f019ed70..d3c651829 100644 --- a/src/search.c +++ b/src/search.c @@ -5059,8 +5059,7 @@ find_pattern_in_path( prev_fname = NULL; } } - vim_free(new_fname); - new_fname = NULL; + VIM_CLEAR(new_fname); already_searched = TRUE; break; } diff --git a/src/spell.c b/src/spell.c index cdcf82295..3c53d1d25 100644 --- a/src/spell.c +++ b/src/spell.c @@ -1994,19 +1994,13 @@ slang_clear(slang_T *lp) int i; int round; - vim_free(lp->sl_fbyts); - lp->sl_fbyts = NULL; - vim_free(lp->sl_kbyts); - lp->sl_kbyts = NULL; - vim_free(lp->sl_pbyts); - lp->sl_pbyts = NULL; - - vim_free(lp->sl_fidxs); - lp->sl_fidxs = NULL; - vim_free(lp->sl_kidxs); - lp->sl_kidxs = NULL; - vim_free(lp->sl_pidxs); - lp->sl_pidxs = NULL; + VIM_CLEAR(lp->sl_fbyts); + VIM_CLEAR(lp->sl_kbyts); + VIM_CLEAR(lp->sl_pbyts); + + VIM_CLEAR(lp->sl_fidxs); + VIM_CLEAR(lp->sl_kidxs); + VIM_CLEAR(lp->sl_pidxs); for (round = 1; round <= 2; ++round) { @@ -2048,26 +2042,19 @@ slang_clear(slang_T *lp) for (i = 0; i < lp->sl_prefixcnt; ++i) vim_regfree(lp->sl_prefprog[i]); lp->sl_prefixcnt = 0; - vim_free(lp->sl_prefprog); - lp->sl_prefprog = NULL; + VIM_CLEAR(lp->sl_prefprog); - vim_free(lp->sl_info); - lp->sl_info = NULL; + VIM_CLEAR(lp->sl_info); - vim_free(lp->sl_midword); - lp->sl_midword = NULL; + VIM_CLEAR(lp->sl_midword); vim_regfree(lp->sl_compprog); - vim_free(lp->sl_comprules); - vim_free(lp->sl_compstartflags); - vim_free(lp->sl_compallflags); lp->sl_compprog = NULL; - lp->sl_comprules = NULL; - lp->sl_compstartflags = NULL; - lp->sl_compallflags = NULL; + VIM_CLEAR(lp->sl_comprules); + VIM_CLEAR(lp->sl_compstartflags); + VIM_CLEAR(lp->sl_compallflags); - vim_free(lp->sl_syllable); - lp->sl_syllable = NULL; + VIM_CLEAR(lp->sl_syllable); ga_clear(&lp->sl_syl_items); ga_clear_strings(&lp->sl_comppat); @@ -2094,10 +2081,8 @@ slang_clear(slang_T *lp) void slang_clear_sug(slang_T *lp) { - vim_free(lp->sl_sbyts); - lp->sl_sbyts = NULL; - vim_free(lp->sl_sidxs); - lp->sl_sidxs = NULL; + VIM_CLEAR(lp->sl_sbyts); + VIM_CLEAR(lp->sl_sidxs); close_spellbuf(lp->sl_sugbuf); lp->sl_sugbuf = NULL; lp->sl_sugloaded = FALSE; @@ -2671,8 +2656,7 @@ clear_midword(win_T *wp) { vim_memset(wp->w_s->b_spell_ismw, 0, 256); #ifdef FEAT_MBYTE - vim_free(wp->w_s->b_spell_ismw_mb); - wp->w_s->b_spell_ismw_mb = NULL; + VIM_CLEAR(wp->w_s->b_spell_ismw_mb); #endif } @@ -2859,8 +2843,7 @@ spell_delete_wordlist(void) mch_remove(int_wordlist); int_wordlist_spl(fname); mch_remove(fname); - vim_free(int_wordlist); - int_wordlist = NULL; + VIM_CLEAR(int_wordlist); } } @@ -2887,10 +2870,8 @@ spell_free_all(void) spell_delete_wordlist(); - vim_free(repl_to); - repl_to = NULL; - vim_free(repl_from); - repl_from = NULL; + VIM_CLEAR(repl_to); + VIM_CLEAR(repl_from); } #endif @@ -3425,10 +3406,8 @@ spell_suggest(int count) } else { - vim_free(repl_from); - repl_from = NULL; - vim_free(repl_to); - repl_to = NULL; + VIM_CLEAR(repl_from); + VIM_CLEAR(repl_to); #ifdef FEAT_RIGHTLEFT /* When 'rightleft' is set the list is drawn right-left. */ diff --git a/src/spellfile.c b/src/spellfile.c index e5cc84164..e9eacbecb 100644 --- a/src/spellfile.c +++ b/src/spellfile.c @@ -1352,8 +1352,7 @@ read_compound(FILE *fd, slang_T *slang, int len) { if (c == '?' || c == '+' || c == '*') { - vim_free(slang->sl_comprules); - slang->sl_comprules = NULL; + VIM_CLEAR(slang->sl_comprules); crp = NULL; } else diff --git a/src/syntax.c b/src/syntax.c index d247e0d16..e85dca76d 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -1189,8 +1189,7 @@ syn_stack_free_block(synblock_T *block) { for (p = block->b_sst_first; p != NULL; p = p->sst_next) clear_syn_state(p); - vim_free(block->b_sst_array); - block->b_sst_array = NULL; + VIM_CLEAR(block->b_sst_array); block->b_sst_len = 0; } } @@ -2134,7 +2133,7 @@ syn_current_attr( r = syn_regexec(®match, current_lnum, (colnr_T)lc_col, - IF_SYN_TIME(&spp->sp_time)); + IF_SYN_TIME(&spp->sp_time)); spp->sp_prog = regmatch.regprog; if (!r) { @@ -3641,8 +3640,7 @@ syntax_clear(synblock_T *block) vim_regfree(block->b_syn_linecont_prog); block->b_syn_linecont_prog = NULL; - vim_free(block->b_syn_linecont_pat); - block->b_syn_linecont_pat = NULL; + VIM_CLEAR(block->b_syn_linecont_pat); #ifdef FEAT_FOLDING block->b_syn_folditems = 0; #endif @@ -3690,8 +3688,7 @@ syntax_sync_clear(void) vim_regfree(curwin->w_s->b_syn_linecont_prog); curwin->w_s->b_syn_linecont_prog = NULL; - vim_free(curwin->w_s->b_syn_linecont_pat); - curwin->w_s->b_syn_linecont_pat = NULL; + VIM_CLEAR(curwin->w_s->b_syn_linecont_pat); clear_string_option(&curwin->w_s->b_syn_isk); syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ @@ -3810,8 +3807,7 @@ syn_cmd_clear(exarg_T *eap, int syncing) */ short scl_id = id - SYNID_CLUSTER; - vim_free(SYN_CLSTR(curwin->w_s)[scl_id].scl_list); - SYN_CLSTR(curwin->w_s)[scl_id].scl_list = NULL; + VIM_CLEAR(SYN_CLSTR(curwin->w_s)[scl_id].scl_list); } } else @@ -5954,8 +5950,7 @@ syn_cmd_sync(exarg_T *eap, int syncing UNUSED) if (curwin->w_s->b_syn_linecont_prog == NULL) { - vim_free(curwin->w_s->b_syn_linecont_pat); - curwin->w_s->b_syn_linecont_pat = NULL; + VIM_CLEAR(curwin->w_s->b_syn_linecont_pat); finished = TRUE; break; } @@ -8369,10 +8364,8 @@ highlight_clear(int idx) HL_TABLE()[idx].sg_cleared = TRUE; HL_TABLE()[idx].sg_term = 0; - vim_free(HL_TABLE()[idx].sg_start); - HL_TABLE()[idx].sg_start = NULL; - vim_free(HL_TABLE()[idx].sg_stop); - HL_TABLE()[idx].sg_stop = NULL; + VIM_CLEAR(HL_TABLE()[idx].sg_start); + VIM_CLEAR(HL_TABLE()[idx].sg_stop); HL_TABLE()[idx].sg_term_attr = 0; HL_TABLE()[idx].sg_cterm = 0; HL_TABLE()[idx].sg_cterm_bold = FALSE; @@ -8381,12 +8374,9 @@ highlight_clear(int idx) HL_TABLE()[idx].sg_cterm_attr = 0; #if defined(FEAT_GUI) || defined(FEAT_EVAL) HL_TABLE()[idx].sg_gui = 0; - vim_free(HL_TABLE()[idx].sg_gui_fg_name); - HL_TABLE()[idx].sg_gui_fg_name = NULL; - vim_free(HL_TABLE()[idx].sg_gui_bg_name); - HL_TABLE()[idx].sg_gui_bg_name = NULL; - vim_free(HL_TABLE()[idx].sg_gui_sp_name); - HL_TABLE()[idx].sg_gui_sp_name = NULL; + VIM_CLEAR(HL_TABLE()[idx].sg_gui_fg_name); + VIM_CLEAR(HL_TABLE()[idx].sg_gui_bg_name); + VIM_CLEAR(HL_TABLE()[idx].sg_gui_sp_name); #endif #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) HL_TABLE()[idx].sg_gui_fg = INVALCOLOR; @@ -8400,8 +8390,7 @@ highlight_clear(int idx) gui_mch_free_fontset(HL_TABLE()[idx].sg_fontset); HL_TABLE()[idx].sg_fontset = NOFONTSET; # endif - vim_free(HL_TABLE()[idx].sg_font_name); - HL_TABLE()[idx].sg_font_name = NULL; + VIM_CLEAR(HL_TABLE()[idx].sg_font_name); HL_TABLE()[idx].sg_gui_attr = 0; #endif #ifdef FEAT_EVAL @@ -1091,8 +1091,7 @@ end_do_tag: void tag_freematch(void) { - vim_free(tagmatchname); - tagmatchname = NULL; + VIM_CLEAR(tagmatchname); } static void @@ -2620,10 +2619,7 @@ free_tag_stuff(void) # if defined(FEAT_QUICKFIX) if (ptag_entry.tagname) - { - vim_free(ptag_entry.tagname); - ptag_entry.tagname = NULL; - } + VIM_CLEAR(ptag_entry.tagname); # endif } #endif diff --git a/src/term.c b/src/term.c index 6303e10d5..1f17d9f2f 100644 --- a/src/term.c +++ b/src/term.c @@ -2502,7 +2502,8 @@ out_flush(void) } /* - * out_flush_cursor(): flush the output buffer and redraw the cursor + * out_flush_cursor(): flush the output buffer and redraw the cursor. + * Does not flush recursively in the GUI to avoid slow drawing. */ void out_flush_cursor( @@ -3912,8 +3913,7 @@ clear_termcodes(void) { while (tc_len > 0) vim_free(termcodes[--tc_len].code); - vim_free(termcodes); - termcodes = NULL; + VIM_CLEAR(termcodes); tc_max_len = 0; #ifdef HAVE_TGETENT @@ -5648,7 +5648,7 @@ check_termcode( /* Work out our pseudo mouse event. Note that MOUSE_RELEASE gets * added, then it's not mouse up/down. */ key_name[0] = (int)KS_EXTRA; - if (wheel_code != 0 + if (wheel_code != 0 && (wheel_code & MOUSE_RELEASE) != MOUSE_RELEASE) { if (wheel_code & MOUSE_CTRL) diff --git a/src/terminal.c b/src/terminal.c index 02d071525..b67cd6ceb 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -1176,8 +1176,7 @@ move_terminal_to_buffer(term_T *term) set_terminal_mode(term_T *term, int normal_mode) { term->tl_normal_mode = normal_mode; - vim_free(term->tl_status_text); - term->tl_status_text = NULL; + VIM_CLEAR(term->tl_status_text); if (term->tl_buffer == curbuf) maketitle(); } @@ -1739,10 +1738,8 @@ term_job_ended(job_T *job) for (term = first_term; term != NULL; term = term->tl_next) if (term->tl_job == job) { - vim_free(term->tl_title); - term->tl_title = NULL; - vim_free(term->tl_status_text); - term->tl_status_text = NULL; + VIM_CLEAR(term->tl_title); + VIM_CLEAR(term->tl_status_text); redraw_buf_and_status_later(term->tl_buffer, VALID); did_one = TRUE; } @@ -2023,8 +2020,7 @@ handle_settermprop( #endif else term->tl_title = vim_strsave((char_u *)value->string); - vim_free(term->tl_status_text); - term->tl_status_text = NULL; + VIM_CLEAR(term->tl_status_text); if (term == curbuf->b_term) maketitle(); break; @@ -2189,10 +2185,8 @@ term_channel_closed(channel_T *ch) term->tl_channel_closed = TRUE; did_one = TRUE; - vim_free(term->tl_title); - term->tl_title = NULL; - vim_free(term->tl_status_text); - term->tl_status_text = NULL; + VIM_CLEAR(term->tl_title); + VIM_CLEAR(term->tl_status_text); /* Unless in Terminal-Normal mode: clear the vterm. */ if (!term->tl_normal_mode) @@ -130,8 +130,7 @@ ui_inchar( if (maxlen >= ta_len - ta_off) { mch_memmove(buf, ta_str + ta_off, (size_t)ta_len); - vim_free(ta_str); - ta_str = NULL; + VIM_CLEAR(ta_str); return ta_len; } mch_memmove(buf, ta_str + ta_off, (size_t)maxlen); @@ -1840,10 +1839,7 @@ fill_input_buf(int exit_on_error UNUSED) unconverted = restlen; mch_memmove(inbuf + inbufcount, rest, unconverted); if (unconverted == restlen) - { - vim_free(rest); - rest = NULL; - } + VIM_CLEAR(rest); else { restlen -= unconverted; diff --git a/src/undo.c b/src/undo.c index 0297e3f66..c723eba6c 100644 --- a/src/undo.c +++ b/src/undo.c @@ -849,8 +849,7 @@ u_get_undo_file_name(char_u *buf_ffname, int reading) if (undo_file_name != NULL && (!reading || mch_stat((char *)undo_file_name, &st) >= 0)) break; - vim_free(undo_file_name); - undo_file_name = NULL; + VIM_CLEAR(undo_file_name); } vim_free(munged_name); @@ -3454,8 +3453,7 @@ u_clearline(void) { if (curbuf->b_u_line_ptr != NULL) { - vim_free(curbuf->b_u_line_ptr); - curbuf->b_u_line_ptr = NULL; + VIM_CLEAR(curbuf->b_u_line_ptr); curbuf->b_u_line_lnum = 0; } } diff --git a/src/userfunc.c b/src/userfunc.c index 931683d7c..df72e34a8 100644 --- a/src/userfunc.c +++ b/src/userfunc.c @@ -2122,10 +2122,7 @@ ex_function(exarg_T *eap) /* between ":append" and "." and between ":python <<EOF" and "EOF" * don't check for ":endfunc". */ if (STRCMP(theline, skip_until) == 0) - { - vim_free(skip_until); - skip_until = NULL; - } + VIM_CLEAR(skip_until); } else { @@ -2295,8 +2292,7 @@ ex_function(exarg_T *eap) /* redefine existing function */ ga_clear_strings(&(fp->uf_args)); ga_clear_strings(&(fp->uf_lines)); - vim_free(name); - name = NULL; + VIM_CLEAR(name); } } } diff --git a/src/version.c b/src/version.c index 3a354753a..dbd272109 100644 --- a/src/version.c +++ b/src/version.c @@ -772,6 +772,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1496, +/**/ 1495, /**/ 1494, diff --git a/src/window.c b/src/window.c index 669f3bd6e..38e1591cc 100644 --- a/src/window.c +++ b/src/window.c @@ -4415,8 +4415,7 @@ win_enter_ext( /* Window doesn't have a local directory and we are not in the global * directory: Change to the global directory. */ ignored = mch_chdir((char *)globaldir); - vim_free(globaldir); - globaldir = NULL; + VIM_CLEAR(globaldir); shorten_fnames(TRUE); } @@ -4847,10 +4846,7 @@ win_free_lsize(win_T *wp) { /* TODO: why would wp be NULL here? */ if (wp != NULL) - { - vim_free(wp->w_lines); - wp->w_lines = NULL; - } + VIM_CLEAR(wp->w_lines); } /* |