# HG changeset patch # User Bram Moolenaar # Date 1586713505 -7200 # Node ID aadd1cae2ff5c8887c87baaab027c6a429b09347 # Parent aee3c926696852db3395f155bd6595f6135f2bf0 patch 8.2.0559: clearing a struct is verbose Commit: https://github.com/vim/vim/commit/a80faa8930ed5a554beeb2727762538873135e83 Author: Bram Moolenaar Date: Sun Apr 12 19:37:17 2020 +0200 patch 8.2.0559: clearing a struct is verbose Problem: Clearing a struct is verbose. Solution: Define and use CLEAR_FIELD() and CLEAR_POINTER(). diff --git a/src/blowfish.c b/src/blowfish.c --- a/src/blowfish.c +++ b/src/blowfish.c @@ -514,7 +514,7 @@ bf_self_test(void) UINT32_T ui = 0xffffffffUL; bf_state_T state; - vim_memset(&state, 0, sizeof(bf_state_T)); + CLEAR_FIELD(state); state.cfb_len = BF_MAX_CFB_LEN; // We can't simply use sizeof(UINT32_T), it would generate a compiler diff --git a/src/channel.c b/src/channel.c --- a/src/channel.c +++ b/src/channel.c @@ -977,7 +977,7 @@ channel_open( // Get the server internet address and put into addr structure fill in the // socket address structure and connect to server. #ifdef FEAT_IPV6 - vim_memset(&hints, 0, sizeof(hints)); + CLEAR_FIELD(hints); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; # ifdef AI_ADDRCONFIG @@ -1037,7 +1037,7 @@ channel_open( freeaddrinfo(res); #else - vim_memset((char *)&server, 0, sizeof(server)); + CLEAR_FIELD(server); server.sin_family = AF_INET; server.sin_port = htons(port); if ((host = gethostbyname(hostname)) == NULL) @@ -2514,7 +2514,7 @@ channel_exe_cmd(channel_T *channel, ch_p exarg_T ea; ch_log(channel, "Executing normal command '%s'", (char *)arg); - vim_memset(&ea, 0, sizeof(ea)); + CLEAR_FIELD(ea); ea.arg = arg; ea.addr_count = 0; ea.forceit = TRUE; // no mapping @@ -2525,7 +2525,7 @@ channel_exe_cmd(channel_T *channel, ch_p exarg_T ea; ch_log(channel, "redraw"); - vim_memset(&ea, 0, sizeof(ea)); + CLEAR_FIELD(ea); ea.forceit = *arg != NUL; ex_redraw(&ea); showruler(FALSE); @@ -4793,7 +4793,7 @@ handle_io(typval_T *item, ch_part_T part void clear_job_options(jobopt_T *opt) { - vim_memset(opt, 0, sizeof(jobopt_T)); + CLEAR_POINTER(opt); } /* diff --git a/src/charset.c b/src/charset.c --- a/src/charset.c +++ b/src/charset.c @@ -127,7 +127,7 @@ buf_init_chartab( /* * Init word char flags all to FALSE */ - vim_memset(buf->b_chartab, 0, (size_t)32); + CLEAR_FIELD(buf->b_chartab); if (enc_dbcs != 0) for (c = 0; c < 256; ++c) { diff --git a/src/clipboard.c b/src/clipboard.c --- a/src/clipboard.c +++ b/src/clipboard.c @@ -2033,7 +2033,7 @@ clip_get_selection(Clipboard_T *cbd) clear_oparg(&oa); oa.regname = (cbd == &clip_plus ? '+' : '*'); oa.op_type = OP_YANK; - vim_memset(&ca, 0, sizeof(ca)); + CLEAR_FIELD(ca); ca.oap = &oa; ca.cmdchar = 'y'; ca.count1 = 1; diff --git a/src/diff.c b/src/diff.c --- a/src/diff.c +++ b/src/diff.c @@ -939,14 +939,14 @@ ex_diffupdate(exarg_T *eap) // "eap" can goto theend; // Only use the internal method if it did not fail for one of the buffers. - vim_memset(&diffio, 0, sizeof(diffio)); + CLEAR_FIELD(diffio); diffio.dio_internal = diff_internal() && !diff_internal_failed(); diff_try_update(&diffio, idx_orig, eap); if (diffio.dio_internal && diff_internal_failed()) { // Internal diff failed, use external diff instead. - vim_memset(&diffio, 0, sizeof(diffio)); + CLEAR_FIELD(diffio); diff_try_update(&diffio, idx_orig, eap); } @@ -1075,9 +1075,9 @@ diff_file_internal(diffio_T *diffio) xdemitconf_t emit_cfg; xdemitcb_t emit_cb; - vim_memset(¶m, 0, sizeof(param)); - vim_memset(&emit_cfg, 0, sizeof(emit_cfg)); - vim_memset(&emit_cb, 0, sizeof(emit_cb)); + CLEAR_FIELD(param); + CLEAR_FIELD(emit_cfg); + CLEAR_FIELD(emit_cb); param.flags = diff_algorithm; diff --git a/src/eval.c b/src/eval.c --- a/src/eval.c +++ b/src/eval.c @@ -234,7 +234,7 @@ eval_expr_typval(typval_T *expr, typval_ s = expr->vval.v_string; if (s == NULL || *s == NUL) return FAIL; - vim_memset(&funcexe, 0, sizeof(funcexe)); + CLEAR_FIELD(funcexe); funcexe.evaluate = TRUE; if (call_func(s, -1, rettv, argc, argv, &funcexe) == FAIL) return FAIL; @@ -253,7 +253,7 @@ eval_expr_typval(typval_T *expr, typval_ s = partial_name(partial); if (s == NULL || *s == NUL) return FAIL; - vim_memset(&funcexe, 0, sizeof(funcexe)); + CLEAR_FIELD(funcexe); funcexe.evaluate = TRUE; funcexe.partial = partial; if (call_func(s, -1, rettv, argc, argv, &funcexe) == FAIL) @@ -475,7 +475,7 @@ call_vim_function( funcexe_T funcexe; rettv->v_type = VAR_UNKNOWN; // clear_tv() uses this - vim_memset(&funcexe, 0, sizeof(funcexe)); + CLEAR_FIELD(funcexe); funcexe.firstline = curwin->w_cursor.lnum; funcexe.lastline = curwin->w_cursor.lnum; funcexe.evaluate = TRUE; @@ -649,7 +649,7 @@ get_lval( int quiet = flags & GLV_QUIET; // Clear everything in "lp". - vim_memset(lp, 0, sizeof(lval_T)); + CLEAR_POINTER(lp); if (skip) { @@ -1715,7 +1715,7 @@ eval_func( funcexe_T funcexe; // Invoke the function. - vim_memset(&funcexe, 0, sizeof(funcexe)); + CLEAR_FIELD(funcexe); funcexe.firstline = curwin->w_cursor.lnum; funcexe.lastline = curwin->w_cursor.lnum; funcexe.evaluate = evaluate; @@ -2805,7 +2805,7 @@ call_func_rettv( else s = (char_u *)""; - vim_memset(&funcexe, 0, sizeof(funcexe)); + CLEAR_FIELD(funcexe); funcexe.firstline = curwin->w_cursor.lnum; funcexe.lastline = curwin->w_cursor.lnum; funcexe.evaluate = evaluate; @@ -5507,7 +5507,7 @@ clear_tv(typval_T *varp) init_tv(typval_T *varp) { if (varp != NULL) - vim_memset(varp, 0, sizeof(typval_T)); + CLEAR_POINTER(varp); } /* diff --git a/src/evalfunc.c b/src/evalfunc.c --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -2977,7 +2977,7 @@ f_get(typval_T *argvars, typval_T *rettv pt = argvars[0].vval.v_partial; else { - vim_memset(&fref_pt, 0, sizeof(fref_pt)); + CLEAR_FIELD(fref_pt); fref_pt.pt_name = argvars[0].vval.v_string; pt = &fref_pt; } @@ -6530,7 +6530,7 @@ search_cmn(typval_T *argvars, pos_T *mat } pos = save_cursor = curwin->w_cursor; - vim_memset(&sia, 0, sizeof(sia)); + CLEAR_FIELD(sia); sia.sa_stop_lnum = (linenr_T)lnum_stop; #ifdef FEAT_RELTIME sia.sa_tm = &tm; @@ -6978,7 +6978,7 @@ do_searchpair( { searchit_arg_T sia; - vim_memset(&sia, 0, sizeof(sia)); + CLEAR_FIELD(sia); sia.sa_stop_lnum = lnum_stop; #ifdef FEAT_RELTIME sia.sa_tm = &tm; @@ -8401,7 +8401,7 @@ f_synconcealed(typval_T *argvars UNUSED, lnum = tv_get_lnum(argvars); // -1 on type error col = (colnr_T)tv_get_number(&argvars[1]) - 1; // -1 on type error - vim_memset(str, NUL, sizeof(str)); + CLEAR_FIELD(str); if (rettv_list_alloc(rettv) != FAIL) { diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c --- a/src/ex_cmds2.c +++ b/src/ex_cmds2.c @@ -168,7 +168,7 @@ dialog_changed( // Init ea pseudo-structure, this is needed for the check_overwrite() // function. - vim_memset(&ea, 0, sizeof(ea)); + CLEAR_FIELD(ea); if (ret == VIM_YES) { @@ -889,7 +889,7 @@ source_pyx_file(exarg_T *eap, char_u *fn * unobtrusive message. */ if (eap == NULL) - vim_memset(&ex, 0, sizeof(ex)); + CLEAR_FIELD(ex); else ex = *eap; ex.arg = fname; diff --git a/src/ex_docmd.c b/src/ex_docmd.c --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -728,7 +728,7 @@ do_cmdline( if (flags & DOCMD_EXCRESET) save_dbg_stuff(&debug_saved); else - vim_memset(&debug_saved, 0, sizeof(debug_saved)); + CLEAR_FIELD(debug_saved); initial_trylevel = trylevel; @@ -1663,7 +1663,7 @@ do_one_cmd( int starts_with_colon; #endif - vim_memset(&ea, 0, sizeof(ea)); + CLEAR_FIELD(ea); ea.line1 = 1; ea.line2 = 1; #ifdef FEAT_EVAL @@ -2626,7 +2626,7 @@ parse_command_modifiers(exarg_T *eap, ch { char_u *p; - vim_memset(&cmdmod, 0, sizeof(cmdmod)); + CLEAR_FIELD(cmdmod); eap->verbose_save = -1; eap->save_msg_silent = -1; @@ -5631,7 +5631,7 @@ handle_drop_internal(void) * Move to the first file. */ // Fake up a minimal "next" command for do_argfile() - vim_memset(&ea, 0, sizeof(ea)); + CLEAR_FIELD(ea); ea.cmd = (char_u *)"next"; do_argfile(&ea, 0); @@ -5898,7 +5898,7 @@ tabpage_new(void) { exarg_T ea; - vim_memset(&ea, 0, sizeof(ea)); + CLEAR_FIELD(ea); ea.cmdidx = CMD_tabnew; ea.cmd = (char_u *)"tabn"; ea.arg = (char_u *)""; diff --git a/src/ex_getln.c b/src/ex_getln.c --- a/src/ex_getln.c +++ b/src/ex_getln.c @@ -218,7 +218,7 @@ do_incsearch_highlighting(int firstc, in return FALSE; ++emsg_off; - vim_memset(&ea, 0, sizeof(ea)); + CLEAR_FIELD(ea); ea.line1 = 1; ea.line2 = 1; ea.cmd = ccline.cmdbuff; @@ -459,7 +459,7 @@ may_do_incsearch_highlighting( search_flags += SEARCH_START; ccline.cmdbuff[skiplen + patlen] = NUL; #ifdef FEAT_RELTIME - vim_memset(&sia, 0, sizeof(sia)); + CLEAR_FIELD(sia); sia.sa_tm = &tm; #endif found = do_search(NULL, firstc == ':' ? '/' : firstc, search_delim, @@ -758,7 +758,7 @@ cmdline_has_arabic(int start, int len) void cmdline_init(void) { - vim_memset(&ccline, 0, sizeof(cmdline_info_T)); + CLEAR_FIELD(ccline); } /* @@ -834,7 +834,7 @@ getcmdline_int( did_save_ccline = TRUE; } if (init_ccline) - vim_memset(&ccline, 0, sizeof(cmdline_info_T)); + CLEAR_FIELD(ccline); #ifdef FEAT_EVAL if (firstc == -1) @@ -2464,7 +2464,7 @@ getcmdline_prompt( did_save_ccline = TRUE; } - vim_memset(&ccline, 0, sizeof(cmdline_info_T)); + CLEAR_FIELD(ccline); ccline.cmdprompt = prompt; ccline.cmdattr = attr; # ifdef FEAT_EVAL @@ -3504,7 +3504,7 @@ save_cmdline(cmdline_info_T *ccp) { if (!prev_ccline_used) { - vim_memset(&prev_ccline, 0, sizeof(cmdline_info_T)); + CLEAR_FIELD(prev_ccline); prev_ccline_used = TRUE; } *ccp = prev_ccline; diff --git a/src/findfile.c b/src/findfile.c --- a/src/findfile.c +++ b/src/findfile.c @@ -320,10 +320,9 @@ vim_findfile_init( search_ctx = search_ctx_arg; else { - search_ctx = ALLOC_ONE(ff_search_ctx_T); + search_ctx = ALLOC_CLEAR_ONE(ff_search_ctx_T); if (search_ctx == NULL) goto error_return; - vim_memset(search_ctx, 0, sizeof(ff_search_ctx_T)); } search_ctx->ffsc_find_what = find_what; search_ctx->ffsc_tagfile = tagfile; diff --git a/src/gui_gtk_f.c b/src/gui_gtk_f.c --- a/src/gui_gtk_f.c +++ b/src/gui_gtk_f.c @@ -223,7 +223,7 @@ gtk_form_get_type(void) { GtkTypeInfo form_info; - vim_memset(&form_info, 0, sizeof(form_info)); + CLEAR_FIELD(form_info); form_info.type_name = "GtkForm"; form_info.object_size = sizeof(GtkForm); form_info.class_size = sizeof(GtkFormClass); diff --git a/src/gui_mac.c b/src/gui_mac.c --- a/src/gui_mac.c +++ b/src/gui_mac.c @@ -5451,7 +5451,7 @@ gui_mch_dialog( button = 0; // initialize the hotkey mapping - vim_memset(hotKeys, 0, sizeof(hotKeys)); + CLEAR_FIELD(hotKeys); for (;*buttonChar != 0;) { diff --git a/src/gui_motif.c b/src/gui_motif.c --- a/src/gui_motif.c +++ b/src/gui_motif.c @@ -1956,7 +1956,7 @@ do_mnemonic(Widget w, unsigned int keyco XmProcessTraversal(w, XmTRAVERSE_CURRENT); - vim_memset((char *) &keyEvent, 0, sizeof(XKeyPressedEvent)); + CLEAR_FIELD(keyEvent); keyEvent.type = KeyPress; keyEvent.serial = 1; keyEvent.send_event = True; diff --git a/src/gui_w32.c b/src/gui_w32.c --- a/src/gui_w32.c +++ b/src/gui_w32.c @@ -3504,7 +3504,7 @@ gui_mch_browse( // Convert the filter to Windows format. filterp = convert_filterW(filter); - vim_memset(&fileStruct, 0, sizeof(OPENFILENAMEW)); + CLEAR_FIELD(fileStruct); # ifdef OPENFILENAME_SIZE_VERSION_400W // be compatible with Windows NT 4.0 fileStruct.lStructSize = OPENFILENAME_SIZE_VERSION_400W; @@ -4267,7 +4267,7 @@ init_mouse_wheel(void) // Mouse hovers over popup window, scroll it if possible. mouse_row = wp->w_winrow; mouse_col = wp->w_wincol; - vim_memset(&cap, 0, sizeof(cap)); + CLEAR_FIELD(cap); cap.arg = zDelta < 0 ? MSCR_UP : MSCR_DOWN; cap.cmdchar = zDelta < 0 ? K_MOUSEUP : K_MOUSEDOWN; clear_oparg(&oa); @@ -6478,7 +6478,7 @@ gui_mch_add_menu_item( { TBBUTTON newtb; - vim_memset(&newtb, 0, sizeof(newtb)); + CLEAR_FIELD(newtb); if (menu_is_separator(menu->name)) { newtb.iBitmap = 0; diff --git a/src/gui_x11.c b/src/gui_x11.c --- a/src/gui_x11.c +++ b/src/gui_x11.c @@ -2267,7 +2267,7 @@ gui_mch_get_rgb_color(int r, int g, int return (guicolor_T)available.pixel; #endif colormap = DefaultColormap(gui.dpy, DefaultScreen(gui.dpy)); - vim_memset(&available, 0, sizeof(XColor)); + CLEAR_FIELD(available); available.red = r << 8; available.green = g << 8; available.blue = b << 8; diff --git a/src/hardcopy.c b/src/hardcopy.c --- a/src/hardcopy.c +++ b/src/hardcopy.c @@ -558,7 +558,7 @@ ex_hardcopy(exarg_T *eap) int page_line; int jobsplit; - vim_memset(&settings, 0, sizeof(prt_settings_T)); + CLEAR_FIELD(settings); settings.has_color = TRUE; # ifdef FEAT_POSTSCRIPT @@ -681,7 +681,7 @@ ex_hardcopy(exarg_T *eap) prt_pos_T page_prtpos; // print position at page start int side; - vim_memset(&page_prtpos, 0, sizeof(prt_pos_T)); + CLEAR_FIELD(page_prtpos); page_prtpos.file_line = eap->line1; prtpos = page_prtpos; @@ -1844,7 +1844,7 @@ prt_open_resource(struct prt_ps_resource semsg(_("E624: Can't open file \"%s\""), resource->filename); return FALSE; } - vim_memset(prt_resfile.buffer, NUL, PRT_FILE_BUFFER_LEN); + CLEAR_FIELD(prt_resfile.buffer); // Parse first line to ensure valid resource file prt_resfile.len = (int)fread((char *)prt_resfile.buffer, sizeof(char_u), diff --git a/src/hashtab.c b/src/hashtab.c --- a/src/hashtab.c +++ b/src/hashtab.c @@ -65,7 +65,7 @@ hash_create(void) hash_init(hashtab_T *ht) { // This zeroes all "ht_" entries and all the "hi_key" in "ht_smallarray". - vim_memset(ht, 0, sizeof(hashtab_T)); + CLEAR_POINTER(ht); ht->ht_array = ht->ht_smallarray; ht->ht_mask = HT_INIT_SIZE - 1; } @@ -394,11 +394,12 @@ hash_may_resize( } else oldarray = ht->ht_array; + CLEAR_FIELD(ht->ht_smallarray); } else { // Allocate an array. - newarray = ALLOC_MULT(hashitem_T, newsize); + newarray = ALLOC_CLEAR_MULT(hashitem_T, newsize); if (newarray == NULL) { // Out of memory. When there are NULL items still return OK. @@ -411,7 +412,6 @@ hash_may_resize( } oldarray = ht->ht_array; } - vim_memset(newarray, 0, (size_t)(sizeof(hashitem_T) * newsize)); /* * Move all the items from the old array to the new one, placing them in diff --git a/src/highlight.c b/src/highlight.c --- a/src/highlight.c +++ b/src/highlight.c @@ -2141,7 +2141,7 @@ get_attr_entry(garray_T *table, attrentr return 0; taep = &(((attrentry_T *)table->ga_data)[table->ga_len]); - vim_memset(taep, 0, sizeof(attrentry_T)); + CLEAR_POINTER(taep); taep->ae_attr = aep->ae_attr; #ifdef FEAT_GUI if (table == &gui_attr_table) @@ -2189,7 +2189,7 @@ get_cterm_attr_idx(int attr, int fg, int { attrentry_T at_en; - vim_memset(&at_en, 0, sizeof(attrentry_T)); + CLEAR_FIELD(at_en); #ifdef FEAT_TERMGUICOLORS at_en.ae_u.cterm.fg_rgb = INVALCOLOR; at_en.ae_u.cterm.bg_rgb = INVALCOLOR; @@ -2211,7 +2211,7 @@ get_tgc_attr_idx(int attr, guicolor_T fg { attrentry_T at_en; - vim_memset(&at_en, 0, sizeof(attrentry_T)); + CLEAR_FIELD(at_en); at_en.ae_attr = attr; if (fg == INVALCOLOR && bg == INVALCOLOR) { @@ -2239,7 +2239,7 @@ get_gui_attr_idx(int attr, guicolor_T fg { attrentry_T at_en; - vim_memset(&at_en, 0, sizeof(attrentry_T)); + CLEAR_FIELD(at_en); at_en.ae_attr = attr; at_en.ae_u.gui.fg_color = fg; at_en.ae_u.gui.bg_color = bg; @@ -2298,7 +2298,7 @@ hl_combine_attr(int char_attr, int prim_ new_en = *char_aep; else { - vim_memset(&new_en, 0, sizeof(new_en)); + CLEAR_FIELD(new_en); new_en.ae_u.gui.fg_color = INVALCOLOR; new_en.ae_u.gui.bg_color = INVALCOLOR; new_en.ae_u.gui.sp_color = INVALCOLOR; @@ -2341,7 +2341,7 @@ hl_combine_attr(int char_attr, int prim_ new_en = *char_aep; else { - vim_memset(&new_en, 0, sizeof(new_en)); + CLEAR_FIELD(new_en); #ifdef FEAT_TERMGUICOLORS new_en.ae_u.cterm.bg_rgb = INVALCOLOR; new_en.ae_u.cterm.fg_rgb = INVALCOLOR; @@ -2393,7 +2393,7 @@ hl_combine_attr(int char_attr, int prim_ new_en = *char_aep; else { - vim_memset(&new_en, 0, sizeof(new_en)); + CLEAR_FIELD(new_en); if (char_attr <= HL_ALL) new_en.ae_attr = char_attr; } @@ -3062,7 +3062,7 @@ syn_add_group(char_u *name) return 0; } - vim_memset(&(HL_TABLE()[highlight_ga.ga_len]), 0, sizeof(hl_group_T)); + CLEAR_POINTER(&(HL_TABLE()[highlight_ga.ga_len])); HL_TABLE()[highlight_ga.ga_len].sg_name = name; HL_TABLE()[highlight_ga.ga_len].sg_name_u = name_up; #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) @@ -3262,7 +3262,7 @@ combine_stl_hlt( if (id_alt == 0) { - vim_memset(&hlt[hlcnt + i], 0, sizeof(hl_group_T)); + CLEAR_POINTER(&hlt[hlcnt + i]); hlt[hlcnt + i].sg_term = highlight_attr[hlf]; hlt[hlcnt + i].sg_cterm = highlight_attr[hlf]; # if defined(FEAT_GUI) || defined(FEAT_EVAL) @@ -3457,7 +3457,7 @@ highlight_changed(void) { // Make sure id_S is always valid to simplify code below. Use the last // entry. - vim_memset(&HL_TABLE()[hlcnt + 27], 0, sizeof(hl_group_T)); + CLEAR_POINTER(&HL_TABLE()[hlcnt + 27]); HL_TABLE()[hlcnt + 18].sg_term = highlight_attr[HLF_S]; id_S = hlcnt + 19; } diff --git a/src/if_mzsch.c b/src/if_mzsch.c --- a/src/if_mzsch.c +++ b/src/if_mzsch.c @@ -1927,7 +1927,7 @@ window_new(win_T *win) MZ_GC_REG(); self = scheme_malloc_fail_ok(scheme_malloc_tagged, sizeof(vim_mz_window)); - vim_memset(self, 0, sizeof(vim_mz_window)); + CLEAR_POINTER(self); #ifndef MZ_PRECISE_GC scheme_dont_gc_ptr(self); // because win isn't visible to GC #else @@ -2311,7 +2311,7 @@ buffer_new(buf_T *buf) MZ_GC_REG(); self = scheme_malloc_fail_ok(scheme_malloc_tagged, sizeof(vim_mz_buffer)); - vim_memset(self, 0, sizeof(vim_mz_buffer)); + CLEAR_POINTER(self); #ifndef MZ_PRECISE_GC scheme_dont_gc_ptr(self); // because buf isn't visible to GC #else @@ -2634,8 +2634,7 @@ set_buffer_line_list(void *data, int arg MZ_GC_VAR_IN_REG(1, rest); MZ_GC_REG(); - array = ALLOC_MULT(char *, new_len + 1); - vim_memset(array, 0, (new_len+1) * sizeof(char *)); + array = ALLOC_CLEAR_MULT(char *, new_len + 1); rest = line_list; for (i = 0; i < new_len; ++i) @@ -2818,8 +2817,7 @@ insert_buffer_line_list(void *data, int MZ_GC_VAR_IN_REG(1, rest); MZ_GC_REG(); - array = ALLOC_MULT(char *, size + 1); - vim_memset(array, 0, (size+1) * sizeof(char *)); + array = ALLOC_CLEAR_MULT(char *, size + 1); rest = list; for (i = 0; i < size; ++i) diff --git a/src/if_py_both.h b/src/if_py_both.h --- a/src/if_py_both.h +++ b/src/if_py_both.h @@ -3200,7 +3200,7 @@ FunctionCall(FunctionObject *self, PyObj if (self->argv || self->self) { - vim_memset(&pt, 0, sizeof(partial_T)); + CLEAR_FIELD(pt); set_partial(self, &pt, FALSE); pt_ptr = &pt; } @@ -6420,7 +6420,7 @@ static PyTypeObject CurrentType; static void init_structs(void) { - vim_memset(&OutputType, 0, sizeof(OutputType)); + CLEAR_FIELD(OutputType); OutputType.tp_name = "vim.message"; OutputType.tp_basicsize = sizeof(OutputObject); OutputType.tp_flags = Py_TPFLAGS_DEFAULT; @@ -6440,7 +6440,7 @@ init_structs(void) // OutputType.tp_base = &PyFile_Type; #endif - vim_memset(&IterType, 0, sizeof(IterType)); + CLEAR_FIELD(IterType); IterType.tp_name = "vim.iter"; IterType.tp_basicsize = sizeof(IterObject); IterType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC; @@ -6451,7 +6451,7 @@ init_structs(void) IterType.tp_traverse = (traverseproc)IterTraverse; IterType.tp_clear = (inquiry)IterClear; - vim_memset(&BufferType, 0, sizeof(BufferType)); + CLEAR_FIELD(BufferType); BufferType.tp_name = "vim.buffer"; BufferType.tp_basicsize = sizeof(BufferType); BufferType.tp_dealloc = (destructor)BufferDestructor; @@ -6472,7 +6472,7 @@ init_structs(void) BufferType.tp_setattr = (setattrfunc)BufferSetattr; #endif - vim_memset(&WindowType, 0, sizeof(WindowType)); + CLEAR_FIELD(WindowType); WindowType.tp_name = "vim.window"; WindowType.tp_basicsize = sizeof(WindowObject); WindowType.tp_dealloc = (destructor)WindowDestructor; @@ -6493,7 +6493,7 @@ init_structs(void) WindowType.tp_setattr = (setattrfunc)WindowSetattr; #endif - vim_memset(&TabPageType, 0, sizeof(TabPageType)); + CLEAR_FIELD(TabPageType); TabPageType.tp_name = "vim.tabpage"; TabPageType.tp_basicsize = sizeof(TabPageObject); TabPageType.tp_dealloc = (destructor)TabPageDestructor; @@ -6510,7 +6510,7 @@ init_structs(void) TabPageType.tp_getattr = (getattrfunc)TabPageGetattr; #endif - vim_memset(&BufMapType, 0, sizeof(BufMapType)); + CLEAR_FIELD(BufMapType); BufMapType.tp_name = "vim.bufferlist"; BufMapType.tp_basicsize = sizeof(BufMapObject); BufMapType.tp_as_mapping = &BufMapAsMapping; @@ -6518,7 +6518,7 @@ init_structs(void) BufMapType.tp_iter = BufMapIter; BufferType.tp_doc = "vim buffer list"; - vim_memset(&WinListType, 0, sizeof(WinListType)); + CLEAR_FIELD(WinListType); WinListType.tp_name = "vim.windowlist"; WinListType.tp_basicsize = sizeof(WinListType); WinListType.tp_as_sequence = &WinListAsSeq; @@ -6526,14 +6526,14 @@ init_structs(void) WinListType.tp_doc = "vim window list"; WinListType.tp_dealloc = (destructor)WinListDestructor; - vim_memset(&TabListType, 0, sizeof(TabListType)); + CLEAR_FIELD(TabListType); TabListType.tp_name = "vim.tabpagelist"; TabListType.tp_basicsize = sizeof(TabListType); TabListType.tp_as_sequence = &TabListAsSeq; TabListType.tp_flags = Py_TPFLAGS_DEFAULT; TabListType.tp_doc = "vim tab page list"; - vim_memset(&RangeType, 0, sizeof(RangeType)); + CLEAR_FIELD(RangeType); RangeType.tp_name = "vim.range"; RangeType.tp_basicsize = sizeof(RangeObject); RangeType.tp_dealloc = (destructor)RangeDestructor; @@ -6554,7 +6554,7 @@ init_structs(void) RangeType.tp_getattr = (getattrfunc)RangeGetattr; #endif - vim_memset(&CurrentType, 0, sizeof(CurrentType)); + CLEAR_FIELD(CurrentType); CurrentType.tp_name = "vim.currentdata"; CurrentType.tp_basicsize = sizeof(CurrentObject); CurrentType.tp_flags = Py_TPFLAGS_DEFAULT; @@ -6568,7 +6568,7 @@ init_structs(void) CurrentType.tp_setattr = (setattrfunc)CurrentSetattr; #endif - vim_memset(&DictionaryType, 0, sizeof(DictionaryType)); + CLEAR_FIELD(DictionaryType); DictionaryType.tp_name = "vim.dictionary"; DictionaryType.tp_basicsize = sizeof(DictionaryObject); DictionaryType.tp_dealloc = (destructor)DictionaryDestructor; @@ -6588,7 +6588,7 @@ init_structs(void) DictionaryType.tp_setattr = (setattrfunc)DictionarySetattr; #endif - vim_memset(&ListType, 0, sizeof(ListType)); + CLEAR_FIELD(ListType); ListType.tp_name = "vim.list"; ListType.tp_dealloc = (destructor)ListDestructor; ListType.tp_basicsize = sizeof(ListObject); @@ -6608,7 +6608,7 @@ init_structs(void) ListType.tp_setattr = (setattrfunc)ListSetattr; #endif - vim_memset(&FunctionType, 0, sizeof(FunctionType)); + CLEAR_FIELD(FunctionType); FunctionType.tp_name = "vim.function"; FunctionType.tp_basicsize = sizeof(FunctionObject); FunctionType.tp_dealloc = (destructor)FunctionDestructor; @@ -6625,7 +6625,7 @@ init_structs(void) FunctionType.tp_getattr = (getattrfunc)FunctionGetattr; #endif - vim_memset(&OptionsType, 0, sizeof(OptionsType)); + CLEAR_FIELD(OptionsType); OptionsType.tp_name = "vim.options"; OptionsType.tp_basicsize = sizeof(OptionsObject); OptionsType.tp_as_sequence = &OptionsAsSeq; @@ -6638,7 +6638,7 @@ init_structs(void) OptionsType.tp_clear = (inquiry)OptionsClear; #if PY_VERSION_HEX < 0x030700f0 - vim_memset(&LoaderType, 0, sizeof(LoaderType)); + CLEAR_FIELD(LoaderType); LoaderType.tp_name = "vim.Loader"; LoaderType.tp_basicsize = sizeof(LoaderObject); LoaderType.tp_flags = Py_TPFLAGS_DEFAULT; @@ -6648,7 +6648,7 @@ init_structs(void) #endif #if PY_MAJOR_VERSION >= 3 - vim_memset(&vimmodule, 0, sizeof(vimmodule)); + CLEAR_FIELD(vimmodule); vimmodule.m_name = "vim"; vimmodule.m_doc = "Vim Python interface\n"; vimmodule.m_size = -1; diff --git a/src/insexpand.c b/src/insexpand.c --- a/src/insexpand.c +++ b/src/insexpand.c @@ -2313,7 +2313,7 @@ ins_compl_add_tv(typval_T *tv, int dir) else { word = tv_get_string_chk(tv); - vim_memset(cptext, 0, sizeof(cptext)); + CLEAR_FIELD(cptext); } if (word == NULL || (!empty && *word == NUL)) return FAIL; diff --git a/src/kword_test.c b/src/kword_test.c --- a/src/kword_test.c +++ b/src/kword_test.c @@ -30,7 +30,7 @@ test_isword_funcs_utf8(void) buf_T buf; int c; - vim_memset(&buf, 0, sizeof(buf)); + CLEAR_FIELD(buf); p_enc = (char_u *)"utf-8"; p_isi = (char_u *)""; p_isp = (char_u *)""; diff --git a/src/list.c b/src/list.c --- a/src/list.c +++ b/src/list.c @@ -1443,7 +1443,7 @@ item_compare2(const void *s1, const void copy_tv(&si2->item->li_tv, &argv[1]); rettv.v_type = VAR_UNKNOWN; // clear_tv() uses this - vim_memset(&funcexe, 0, sizeof(funcexe)); + CLEAR_FIELD(funcexe); funcexe.evaluate = TRUE; funcexe.partial = partial; funcexe.selfdict = sortinfo->item_compare_selfdict; diff --git a/src/main.c b/src/main.c --- a/src/main.c +++ b/src/main.c @@ -119,7 +119,7 @@ main // Many variables are in "params" so that we can pass them to invoked // functions without a lot of arguments. "argc" and "argv" are also // copied, so that they can be changed. - vim_memset(¶ms, 0, sizeof(params)); + CLEAR_FIELD(params); params.argc = argc; params.argv = argv; params.want_full_screen = TRUE; diff --git a/src/map.c b/src/map.c --- a/src/map.c +++ b/src/map.c @@ -65,7 +65,7 @@ validate_maphash(void) { if (!maphash_valid) { - vim_memset(maphash, 0, sizeof(maphash)); + CLEAR_FIELD(maphash); maphash_valid = TRUE; } } diff --git a/src/memfile.c b/src/memfile.c --- a/src/memfile.c +++ b/src/memfile.c @@ -1337,7 +1337,7 @@ mf_do_open( static void mf_hash_init(mf_hashtab_T *mht) { - vim_memset(mht, 0, sizeof(mf_hashtab_T)); + CLEAR_POINTER(mht); mht->mht_buckets = mht->mht_small_buckets; mht->mht_mask = MHT_INIT_SIZE - 1; } @@ -1480,7 +1480,7 @@ mf_hash_grow(mf_hashtab_T *mht) * a power of two. */ - vim_memset(tails, 0, sizeof(tails)); + CLEAR_FIELD(tails); for (mhi = mht->mht_buckets[i]; mhi != NULL; mhi = mhi->mhi_next) { diff --git a/src/message_test.c b/src/message_test.c --- a/src/message_test.c +++ b/src/message_test.c @@ -269,7 +269,7 @@ test_vim_snprintf(void) int main(int argc, char **argv) { - vim_memset(¶ms, 0, sizeof(params)); + CLEAR_FIELD(params); params.argc = argc; params.argv = argv; common_init(¶ms); diff --git a/src/misc1.c b/src/misc1.c --- a/src/misc1.c +++ b/src/misc1.c @@ -631,7 +631,7 @@ f_mode(typval_T *argvars, typval_T *rett { char_u buf[4]; - vim_memset(buf, 0, sizeof(buf)); + CLEAR_FIELD(buf); if (time_for_testing == 93784) { diff --git a/src/netbeans.c b/src/netbeans.c --- a/src/netbeans.c +++ b/src/netbeans.c @@ -1547,7 +1547,7 @@ nb_do_cmd( // disappear. do_bufdel(DOBUF_DEL, (char_u *)"", 1, buf->bufp->b_fnum, buf->bufp->b_fnum, TRUE); - vim_memset(buf, 0, sizeof(nbbuf_T)); + CLEAR_POINTER(buf); } } // ===================================================================== diff --git a/src/normal.c b/src/normal.c --- a/src/normal.c +++ b/src/normal.c @@ -500,7 +500,7 @@ normal_cmd( int set_prevcount = FALSE; #endif - vim_memset(&ca, 0, sizeof(ca)); // also resets ca.retval + CLEAR_FIELD(ca); // also resets ca.retval ca.oap = oap; // Use a count remembered from before entering an operator. After typing @@ -3480,7 +3480,7 @@ do_nv_ident(int c1, int c2) cmdarg_T ca; clear_oparg(&oa); - vim_memset(&ca, 0, sizeof(ca)); + CLEAR_FIELD(ca); ca.oap = &oa; ca.cmdchar = c1; ca.nchar = c2; @@ -4308,7 +4308,7 @@ normal_search( cap->oap->use_reg_one = TRUE; curwin->w_set_curswant = TRUE; - vim_memset(&sia, 0, sizeof(sia)); + CLEAR_FIELD(sia); i = do_search(cap->oap, dir, dir, pat, cap->count1, opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, &sia); if (wrapped != NULL) diff --git a/src/ops.c b/src/ops.c --- a/src/ops.c +++ b/src/ops.c @@ -3412,7 +3412,7 @@ theend: void clear_oparg(oparg_T *oap) { - vim_memset(oap, 0, sizeof(oparg_T)); + CLEAR_POINTER(oap); } /* diff --git a/src/option.c b/src/option.c --- a/src/option.c +++ b/src/option.c @@ -1369,7 +1369,7 @@ do_set( } /* - * allow '=' and ':' for hystorical reasons (MSDOS command.com + * allow '=' and ':' for historical reasons (MSDOS command.com * allows only one '=' character per "set" command line. grrr. (jw) */ if (nextchar == '?' @@ -5666,7 +5666,7 @@ buf_copy_options(buf_T *buf, int flags) if (should_copy || (flags & BCO_ALWAYS)) { #ifdef FEAT_EVAL - vim_memset(buf->b_p_script_ctx, 0, sizeof(buf->b_p_script_ctx)); + CLEAR_FIELD(buf->b_p_script_ctx); init_buf_opt_idx(); #endif // Don't copy the options specific to a help buffer when diff --git a/src/os_mswin.c b/src/os_mswin.c --- a/src/os_mswin.c +++ b/src/os_mswin.c @@ -1338,7 +1338,7 @@ mch_print_init(prt_settings_T *psettings int i; bUserAbort = &(psettings->user_abort); - vim_memset(&prt_dlg, 0, sizeof(PRINTDLGW)); + CLEAR_FIELD(prt_dlg); prt_dlg.lStructSize = sizeof(PRINTDLGW); # if !defined(FEAT_GUI) || defined(VIMDLL) # ifdef VIMDLL @@ -1467,7 +1467,7 @@ mch_print_init(prt_settings_T *psettings /* * Initialise the font according to 'printfont' */ - vim_memset(&fLogFont, 0, sizeof(fLogFont)); + CLEAR_FIELD(fLogFont); if (get_logfont(&fLogFont, p_pfn, prt_dlg.hDC, TRUE) == FAIL) { semsg(_("E613: Unknown printer font: %s"), p_pfn); @@ -1562,7 +1562,7 @@ mch_print_begin(prt_settings_T *psetting { DOCINFOW di; - vim_memset(&di, 0, sizeof(di)); + CLEAR_FIELD(di); di.cbSize = sizeof(di); di.lpszDocName = wp; ret = StartDocW(prt_dlg.hDC, &di); @@ -2881,7 +2881,7 @@ get_logfont( # if defined(FEAT_GUI_MSWIN) CHOOSEFONTW cf; // if name is "*", bring up std font dialog: - vim_memset(&cf, 0, sizeof(cf)); + CLEAR_FIELD(cf); cf.lStructSize = sizeof(cf); cf.hwndOwner = s_hwnd; cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_INITTOLOGFONTSTRUCT; diff --git a/src/os_win32.c b/src/os_win32.c --- a/src/os_win32.c +++ b/src/os_win32.c @@ -950,7 +950,7 @@ win32_kbd_patch_key( if (pker->UChar != 0) return 1; - vim_memset(abKeystate, 0, sizeof (abKeystate)); + CLEAR_FIELD(abKeystate); // Clear any pending dead keys ToUnicode(VK_SPACE, MapVirtualKey(VK_SPACE, 0), abKeystate, awAnsiCode, 2, 0); diff --git a/src/popupmenu.c b/src/popupmenu.c --- a/src/popupmenu.c +++ b/src/popupmenu.c @@ -1382,7 +1382,7 @@ pum_execute_menu(vimmenu_T *menu, int mo FOR_ALL_CHILD_MENUS(menu, mp) if ((mp->modes & mp->enabled & mode) && idx++ == pum_selected) { - vim_memset(&ea, 0, sizeof(ea)); + CLEAR_FIELD(ea); execute_menu(&ea, mp, -1); break; } diff --git a/src/quickfix.c b/src/quickfix.c --- a/src/quickfix.c +++ b/src/quickfix.c @@ -1667,8 +1667,8 @@ qf_init_ext( // Do not used the cached buffer, it may have been wiped out. VIM_CLEAR(qf_last_bufname); - vim_memset(&state, 0, sizeof(state)); - vim_memset(&fields, 0, sizeof(fields)); + CLEAR_FIELD(state); + CLEAR_FIELD(fields); if ((qf_alloc_fields(&fields) == FAIL) || (qf_setup_state(&state, enc, efile, tv, buf, lnumfirst, lnumlast) == FAIL)) @@ -1867,7 +1867,7 @@ qf_new_list(qf_info_T *qi, char_u *qf_ti else qi->qf_curlist = qi->qf_listcount++; qfl = qf_get_curlist(qi); - vim_memset(qfl, 0, (size_t)(sizeof(qf_list_T))); + CLEAR_POINTER(qfl); qf_store_title(qfl, qf_title); qfl->qfl_type = qi->qfl_type; qfl->qf_id = ++last_qf_id; @@ -5794,7 +5794,7 @@ vgr_jump_to_match( { exarg_T ea; - vim_memset(&ea, 0, sizeof(ea)); + CLEAR_FIELD(ea); ea.arg = target_dir; ea.cmdidx = CMD_lcd; ex_cd(&ea); @@ -6151,7 +6151,7 @@ restore_start_dir(char_u *dirname_start) // appropriate ex command and executing it. exarg_T ea; - vim_memset(&ea, 0, sizeof(ea)); + CLEAR_FIELD(ea); ea.arg = dirname_start; ea.cmdidx = (curwin->w_localdir == NULL) ? CMD_cd : CMD_lcd; ex_cd(&ea); diff --git a/src/regexp.c b/src/regexp.c --- a/src/regexp.c +++ b/src/regexp.c @@ -2014,7 +2014,7 @@ vim_regsub_both( argv[0].v_type = VAR_LIST; argv[0].vval.v_list = &matchList.sl_list; matchList.sl_list.lv_len = 0; - vim_memset(&funcexe, 0, sizeof(funcexe)); + CLEAR_FIELD(funcexe); funcexe.argv_func = fill_submatch_list; funcexe.evaluate = TRUE; if (expr->v_type == VAR_FUNC) diff --git a/src/regexp_bt.c b/src/regexp_bt.c --- a/src/regexp_bt.c +++ b/src/regexp_bt.c @@ -470,7 +470,7 @@ regcomp_start( num_complex_braces = 0; regnpar = 1; - vim_memset(had_endbrace, 0, sizeof(had_endbrace)); + CLEAR_FIELD(had_endbrace); #ifdef FEAT_SYN_HL regnzpar = 1; re_has_z = 0; diff --git a/src/regexp_nfa.c b/src/regexp_nfa.c --- a/src/regexp_nfa.c +++ b/src/regexp_nfa.c @@ -4564,7 +4564,7 @@ skip_add: // avoid compiler warnings save_ptr = NULL; - vim_memset(&save_multipos, 0, sizeof(save_multipos)); + CLEAR_FIELD(save_multipos); // Set the position (with "off" added) in the subexpression. Save // and restore it when it was in use. Otherwise fill any gap. @@ -4717,7 +4717,7 @@ skip_add: save_ptr = sub->list.line[subidx].end; sub->list.line[subidx].end = rex.input + off; // avoid compiler warnings - vim_memset(&save_multipos, 0, sizeof(save_multipos)); + CLEAR_FIELD(save_multipos); } subs = addstate(l, state->out, subs, pim, off_arg); diff --git a/src/search.c b/src/search.c --- a/src/search.c +++ b/src/search.c @@ -470,7 +470,7 @@ set_last_csearch(int c, char_u *s UNUSED if (len) memcpy(lastc_bytes, s, len); else - vim_memset(lastc_bytes, 0, sizeof(lastc_bytes)); + CLEAR_FIELD(lastc_bytes); } #endif diff --git a/src/sign.c b/src/sign.c --- a/src/sign.c +++ b/src/sign.c @@ -489,7 +489,7 @@ buf_get_signattrs(win_T *wp, linenr_T ln sign_T *sp; buf_T *buf = wp->w_buffer; - vim_memset(sattr, 0, sizeof(sign_attrs_T)); + CLEAR_POINTER(sattr); FOR_ALL_SIGNS_IN_BUF(buf, sign) { diff --git a/src/spell.c b/src/spell.c --- a/src/spell.c +++ b/src/spell.c @@ -183,7 +183,7 @@ spell_check( if (wp->w_s->b_langp.ga_len == 0) return 1; - vim_memset(&mi, 0, sizeof(matchinf_T)); + CLEAR_FIELD(mi); // A number is always OK. Also skip hexadecimal numbers 0xFF99 and // 0X99FF. But always do check spelling to find "3GPP" and "11 @@ -2274,7 +2274,7 @@ theend: static void clear_midword(win_T *wp) { - vim_memset(wp->w_s->b_spell_ismw, 0, 256); + CLEAR_FIELD(wp->w_s->b_spell_ismw); VIM_CLEAR(wp->w_s->b_spell_ismw_mb); } @@ -2520,9 +2520,9 @@ clear_spell_chartab(spelltab_T *sp) { int i; - // Init everything to FALSE. - vim_memset(sp->st_isw, FALSE, sizeof(sp->st_isw)); - vim_memset(sp->st_isu, FALSE, sizeof(sp->st_isu)); + // Init everything to FALSE (zero). + CLEAR_FIELD(sp->st_isw); + CLEAR_FIELD(sp->st_isu); for (i = 0; i < 256; ++i) { sp->st_fold[i] = i; diff --git a/src/spellfile.c b/src/spellfile.c --- a/src/spellfile.c +++ b/src/spellfile.c @@ -4600,7 +4600,7 @@ get_wordnode(spellinfo_T *spin) { n = spin->si_first_free; spin->si_first_free = n->wn_child; - vim_memset(n, 0, sizeof(wordnode_T)); + CLEAR_POINTER(n); --spin->si_free_count; } #ifdef SPELL_PRINTTREE @@ -5886,7 +5886,7 @@ mkspell( int error = FALSE; spellinfo_T spin; - vim_memset(&spin, 0, sizeof(spin)); + CLEAR_FIELD(spin); spin.si_verbose = !added_word; spin.si_ascii = ascii; spin.si_followup = TRUE; diff --git a/src/spellsuggest.c b/src/spellsuggest.c --- a/src/spellsuggest.c +++ b/src/spellsuggest.c @@ -760,7 +760,7 @@ spell_find_suggest( langp_T *lp; // Set the info in "*su". - vim_memset(su, 0, sizeof(suginfo_T)); + CLEAR_POINTER(su); ga_init2(&su->su_ga, (int)sizeof(suggest_T), 10); ga_init2(&su->su_sga, (int)sizeof(suggest_T), 10); if (*badptr == NUL) @@ -1266,7 +1266,7 @@ suggest_trie_walk( // word). depth = 0; sp = &stack[0]; - vim_memset(sp, 0, sizeof(trystate_T)); + CLEAR_POINTER(sp); sp->ts_curi = 1; if (soundfold) diff --git a/src/syntax.c b/src/syntax.c --- a/src/syntax.c +++ b/src/syntax.c @@ -2750,7 +2750,7 @@ push_current_state(int idx) { if (ga_grow(¤t_state, 1) == FAIL) return FAIL; - vim_memset(&CUR_STATE(current_state.ga_len), 0, sizeof(stateitem_T)); + CLEAR_POINTER(&CUR_STATE(current_state.ga_len)); CUR_STATE(current_state.ga_len).si_idx = idx; ++current_state.ga_len; return OK; @@ -4908,7 +4908,7 @@ syn_cmd_match( // get the pattern. init_syn_patterns(); - vim_memset(&item, 0, sizeof(item)); + CLEAR_FIELD(item); rest = get_syn_pattern(rest, &item); if (vim_regcomp_had_eol() && !(syn_opt_arg.flags & HL_EXCLUDENL)) syn_opt_arg.flags |= HL_HAS_EOL; @@ -5481,7 +5481,7 @@ syn_add_cluster(char_u *name) return 0; } - vim_memset(&(SYN_CLSTR(curwin->w_s)[len]), 0, sizeof(syn_cluster_T)); + CLEAR_POINTER(&(SYN_CLSTR(curwin->w_s)[len])); SYN_CLSTR(curwin->w_s)[len].scl_name = name; SYN_CLSTR(curwin->w_s)[len].scl_name_u = vim_strsave_up(name); SYN_CLSTR(curwin->w_s)[len].scl_list = NULL; diff --git a/src/tag.c b/src/tag.c --- a/src/tag.c +++ b/src/tag.c @@ -1753,7 +1753,7 @@ find_tags( #ifdef FEAT_TAG_BINS // This is only to avoid a compiler warning for using search_info // uninitialised. - vim_memset(&search_info, 0, (size_t)1); + CLEAR_FIELD(search_info); #endif #ifdef FEAT_EVAL @@ -2260,7 +2260,7 @@ parse_line: #endif ) { - vim_memset(&tagp, 0, sizeof(tagp)); + CLEAR_FIELD(tagp); tagp.tagname = lbuf; tagp.tagname_end = vim_strchr(lbuf, TAB); if (tagp.tagname_end == NULL) @@ -2873,7 +2873,7 @@ get_tagfname( int i; if (first) - vim_memset(tnp, 0, sizeof(tagname_T)); + CLEAR_POINTER(tnp); if (curbuf->b_help) { diff --git a/src/terminal.c b/src/terminal.c --- a/src/terminal.c +++ b/src/terminal.c @@ -446,7 +446,7 @@ term_start( ga_init2(&term->tl_scrollback, sizeof(sb_line_T), 300); ga_init2(&term->tl_scrollback_postponed, sizeof(sb_line_T), 300); - vim_memset(&split_ea, 0, sizeof(split_ea)); + CLEAR_FIELD(split_ea); if (opt->jo_curwin) { // Create a new buffer in the current window. @@ -1756,7 +1756,7 @@ update_snapshot(term_T *term) if (vterm_screen_get_cell(screen, pos, &cell) == 0) { width = 1; - vim_memset(p + pos.col, 0, sizeof(cellattr_T)); + CLEAR_POINTER(p + pos.col); if (ga_grow(&ga, 1) == OK) ga.ga_len += utf_char2bytes(' ', (char_u *)ga.ga_data + ga.ga_len); @@ -2243,7 +2243,7 @@ term_get_cursor_shape(guicolor_T *fg, gu int id; guicolor_T term_fg, term_bg; - vim_memset(&entry, 0, sizeof(entry)); + CLEAR_FIELD(entry); entry.shape = entry.mshape = term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_UNDERLINE ? SHAPE_HOR : term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_BAR_LEFT ? SHAPE_VER : @@ -2781,7 +2781,7 @@ vtermAttr2hl(VTermScreenCellAttrs cellat static void hl2vtermAttr(int attr, cellattr_T *cell) { - vim_memset(&cell->attrs, 0, sizeof(VTermScreenCellAttrs)); + CLEAR_FIELD(cell->attrs); if (attr & HL_BOLD) cell->attrs.bold = 1; if (attr & HL_UNDERLINE) @@ -2919,7 +2919,7 @@ term_scroll_up(term_T *term, int start_r VTermScreenCellAttrs attr; int clear_attr; - vim_memset(&attr, 0, sizeof(attr)); + CLEAR_FIELD(attr); while (for_all_windows_and_curwin(&wp, &did_curwin)) { @@ -3332,7 +3332,7 @@ term_after_channel_closed(term_T *term) { exarg_T ea; - vim_memset(&ea, 0, sizeof(ea)); + CLEAR_FIELD(ea); ex_quit(&ea); return TRUE; } @@ -3502,7 +3502,7 @@ term_line2screenline( int c; if (vterm_screen_get_cell(screen, *pos, &cell) == 0) - vim_memset(&cell, 0, sizeof(cell)); + CLEAR_FIELD(cell); c = cell.chars[0]; if (c == NUL) @@ -3828,7 +3828,7 @@ init_default_colors(term_T *term, win_T int fgval, bgval; int id; - vim_memset(&term->tl_default_color.attrs, 0, sizeof(VTermScreenCellAttrs)); + CLEAR_FIELD(term->tl_default_color.attrs); term->tl_default_color.width = 1; fg = &term->tl_default_color.fg; bg = &term->tl_default_color.bg; @@ -4070,7 +4070,7 @@ handle_drop_command(listitem_T *item) } } - vim_memset(&ea, 0, sizeof(ea)); + CLEAR_FIELD(ea); if (opt_item != NULL && opt_item->li_tv.v_type == VAR_DICT && opt_item->li_tv.vval.v_dict != NULL) @@ -4163,7 +4163,7 @@ handle_call_command(term_T *term, channe argvars[0].v_type = VAR_NUMBER; argvars[0].vval.v_number = term->tl_buffer->b_fnum; argvars[1] = item->li_next->li_tv; - vim_memset(&funcexe, 0, sizeof(funcexe)); + CLEAR_FIELD(funcexe); funcexe.firstline = 1L; funcexe.lastline = 1L; funcexe.evaluate = TRUE; @@ -4582,7 +4582,7 @@ f_term_dumpwrite(typval_T *argvars, typv return; } - vim_memset(&prev_cell, 0, sizeof(prev_cell)); + CLEAR_FIELD(prev_cell); screen = vterm_obtain_screen(term->tl_vterm); state = vterm_obtain_state(term->tl_vterm); @@ -4604,7 +4604,7 @@ f_term_dumpwrite(typval_T *argvars, typv && pos.row == cursor_pos.row); if (vterm_screen_get_cell(screen, pos, &cell) == 0) - vim_memset(&cell, 0, sizeof(cell)); + CLEAR_FIELD(cell); for (i = 0; i < VTERM_MAX_CHARS_PER_CELL; ++i) { @@ -4742,8 +4742,8 @@ read_dump_file(FILE *fd, VTermPos *curso ga_init2(&ga_text, 1, 90); ga_init2(&ga_cell, sizeof(cellattr_T), 90); - vim_memset(&cell, 0, sizeof(cell)); - vim_memset(&empty_cell, 0, sizeof(empty_cell)); + CLEAR_FIELD(cell); + CLEAR_FIELD(empty_cell); cursor_pos->row = -1; cursor_pos->col = -1; diff --git a/src/time.c b/src/time.c --- a/src/time.c +++ b/src/time.c @@ -313,7 +313,7 @@ f_strptime(typval_T *argvars, typval_T * vimconv_T conv; char_u *enc; - vim_memset(&tmval, NUL, sizeof(tmval)); + CLEAR_FIELD(tmval); fmt = tv_get_string(&argvars[0]); str = tv_get_string(&argvars[1]); diff --git a/src/undo.c b/src/undo.c --- a/src/undo.c +++ b/src/undo.c @@ -662,7 +662,7 @@ u_savecommon( uep = U_ALLOC_LINE(sizeof(u_entry_T)); if (uep == NULL) goto nomem; - vim_memset(uep, 0, sizeof(u_entry_T)); + CLEAR_POINTER(uep); #ifdef U_DEBUG uep->ue_magic = UE_MAGIC; #endif @@ -1288,7 +1288,7 @@ unserialize_uhp(bufinfo_T *bi, char_u *f uhp = U_ALLOC_LINE(sizeof(u_header_T)); if (uhp == NULL) return NULL; - vim_memset(uhp, 0, sizeof(u_header_T)); + CLEAR_POINTER(uhp); #ifdef U_DEBUG uhp->uh_magic = UH_MAGIC; #endif @@ -1405,7 +1405,7 @@ unserialize_uep(bufinfo_T *bi, int *erro uep = U_ALLOC_LINE(sizeof(u_entry_T)); if (uep == NULL) return NULL; - vim_memset(uep, 0, sizeof(u_entry_T)); + CLEAR_POINTER(uep); #ifdef U_DEBUG uep->ue_magic = UE_MAGIC; #endif @@ -1532,7 +1532,7 @@ u_write_undo( #endif bufinfo_T bi; - vim_memset(&bi, 0, sizeof(bi)); + CLEAR_FIELD(bi); if (name == NULL) { @@ -1814,7 +1814,7 @@ u_read_undo(char_u *name, char_u *hash, #endif bufinfo_T bi; - vim_memset(&bi, 0, sizeof(bi)); + CLEAR_FIELD(bi); line_ptr.ul_len = 0; line_ptr.ul_line = NULL; diff --git a/src/userfunc.c b/src/userfunc.c --- a/src/userfunc.c +++ b/src/userfunc.c @@ -1136,7 +1136,7 @@ call_user_func( v->di_tv.v_lock = VAR_FIXED; v->di_tv.vval.v_list = &fc->l_varlist; } - vim_memset(&fc->l_varlist, 0, sizeof(list_T)); + CLEAR_FIELD(fc->l_varlist); fc->l_varlist.lv_refcount = DO_NOT_FREE_CNT; fc->l_varlist.lv_lock = VAR_FIXED; @@ -1659,7 +1659,7 @@ func_call( { funcexe_T funcexe; - vim_memset(&funcexe, 0, sizeof(funcexe)); + CLEAR_FIELD(funcexe); funcexe.firstline = curwin->w_cursor.lnum; funcexe.lastline = curwin->w_cursor.lnum; funcexe.evaluate = TRUE; @@ -1698,7 +1698,7 @@ call_callback( funcexe_T funcexe; int ret; - vim_memset(&funcexe, 0, sizeof(funcexe)); + CLEAR_FIELD(funcexe); funcexe.evaluate = TRUE; funcexe.partial = callback->cb_partial; ++callback_depth; @@ -2052,7 +2052,7 @@ trans_function_name( int vim9script; if (fdp != NULL) - vim_memset(fdp, 0, sizeof(funcdict_T)); + CLEAR_POINTER(fdp); start = *pp; // Check for hard coded : already translated function ID (from a user @@ -3572,7 +3572,7 @@ ex_call(exarg_T *eap) } arg = startarg; - vim_memset(&funcexe, 0, sizeof(funcexe)); + CLEAR_FIELD(funcexe); funcexe.firstline = eap->line1; funcexe.lastline = eap->line2; funcexe.doesrange = &doesrange; diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -739,6 +739,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 559, +/**/ 558, /**/ 557, diff --git a/src/vim.h b/src/vim.h --- a/src/vim.h +++ b/src/vim.h @@ -1575,6 +1575,14 @@ typedef UINT32_TYPEDEF UINT32_T; #define LALLOC_CLEAR_MULT(type, count) (type *)lalloc_clear(sizeof(type) * (count), FALSE) #define LALLOC_MULT(type, count) (type *)lalloc(sizeof(type) * (count), FALSE) +#ifdef HAVE_MEMSET +# define vim_memset(ptr, c, size) memset((ptr), (c), (size)) +#else +void *vim_memset(void *, int, size_t); +#endif +#define CLEAR_FIELD(field) vim_memset(&(field), 0, sizeof(field)) +#define CLEAR_POINTER(ptr) vim_memset((ptr), 0, sizeof(*(ptr))) + /* * defines to avoid typecasts from (char_u *) to (char *) and back * (vim_strchr() and vim_strrchr() are now in alloc.c) @@ -1708,12 +1716,6 @@ typedef void *vim_acl_T; // dummy t #define fnamecmp(x, y) vim_fnamecmp((char_u *)(x), (char_u *)(y)) #define fnamencmp(x, y, n) vim_fnamencmp((char_u *)(x), (char_u *)(y), (size_t)(n)) -#ifdef HAVE_MEMSET -# define vim_memset(ptr, c, size) memset((ptr), (c), (size)) -#else -void *vim_memset(void *, int, size_t); -#endif - #if defined(UNIX) || defined(FEAT_GUI) || defined(VMS) \ || defined(FEAT_CLIENTSERVER) # define USE_INPUT_BUF diff --git a/src/vim9compile.c b/src/vim9compile.c --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -5617,7 +5617,7 @@ compile_def_function(ufunc_T *ufunc, int if (ga_grow(&def_functions, 1) == FAIL) return; dfunc = ((dfunc_T *)def_functions.ga_data) + def_functions.ga_len; - vim_memset(dfunc, 0, sizeof(dfunc_T)); + CLEAR_POINTER(dfunc); dfunc->df_idx = def_functions.ga_len; ufunc->uf_dfunc_idx = dfunc->df_idx; dfunc->df_ufunc = ufunc; @@ -5625,7 +5625,7 @@ compile_def_function(ufunc_T *ufunc, int } } - vim_memset(&cctx, 0, sizeof(cctx)); + CLEAR_FIELD(cctx); cctx.ctx_ufunc = ufunc; cctx.ctx_lnum = -1; ga_init2(&cctx.ctx_locals, sizeof(lvar_T), 10); @@ -5713,7 +5713,7 @@ compile_def_function(ufunc_T *ufunc, int emsg_before = called_emsg; had_return = FALSE; - vim_memset(&ea, 0, sizeof(ea)); + CLEAR_FIELD(ea); ea.cmdlinep = &line; ea.cmd = skipwhite(line); diff --git a/src/vim9execute.c b/src/vim9execute.c --- a/src/vim9execute.c +++ b/src/vim9execute.c @@ -358,7 +358,7 @@ call_ufunc(ufunc_T *ufunc, int argcount, if (call_prepare(argcount, argvars, ectx) == FAIL) return FAIL; - vim_memset(&funcexe, 0, sizeof(funcexe)); + CLEAR_FIELD(funcexe); funcexe.evaluate = TRUE; // Call the user function. Result goes in last position on the stack. @@ -498,7 +498,7 @@ call_def_function( // Get pointer to a local variable on the stack. Negative for arguments. #define STACK_TV_VAR(idx) (((typval_T *)ectx.ec_stack.ga_data) + ectx.ec_frame + STACK_FRAME_SIZE + idx) - vim_memset(&ectx, 0, sizeof(ectx)); + CLEAR_FIELD(ectx); ga_init2(&ectx.ec_stack, sizeof(typval_T), 500); if (ga_grow(&ectx.ec_stack, 20) == FAIL) return FAIL;