To: vim_dev@googlegroups.com Subject: Patch 9.0.1391 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.1391 Problem: "clear" macros are not always used. Solution: Use ALLOC_ONE, VIM_CLEAR, CLEAR_POINTER and CLEAR_FIELD in more places. (Yegappan Lakshmanan, closes #12104) Files: src/buffer.c, src/channel.c, src/debugger.c, src/diff.c, src/evalfunc.c, src/fileio.c, src/gui_photon.c, src/gui_w32.c, src/hardcopy.c, src/indent.c, src/list.c, src/mbyte.c, src/option.c, src/optionstr.c, src/os_qnx.c, src/os_win32.c, src/popupwin.c, src/quickfix.c, src/search.c, src/syntax.c, src/textprop.c, src/userfunc.c *** ../vim-9.0.1390/src/buffer.c 2023-02-20 14:35:16.999853781 +0000 --- src/buffer.c 2023-03-07 17:42:34.804317574 +0000 *************** *** 2375,2382 **** clear_string_option(&buf->b_p_isk); #ifdef FEAT_VARTABS clear_string_option(&buf->b_p_vsts); ! vim_free(buf->b_p_vsts_nopaste); ! buf->b_p_vsts_nopaste = NULL; VIM_CLEAR(buf->b_p_vsts_array); clear_string_option(&buf->b_p_vts); VIM_CLEAR(buf->b_p_vts_array); --- 2375,2381 ---- clear_string_option(&buf->b_p_isk); #ifdef FEAT_VARTABS clear_string_option(&buf->b_p_vsts); ! VIM_CLEAR(buf->b_p_vsts_nopaste); VIM_CLEAR(buf->b_p_vsts_array); clear_string_option(&buf->b_p_vts); VIM_CLEAR(buf->b_p_vts_array); *** ../vim-9.0.1390/src/channel.c 2023-02-21 14:27:34.512360384 +0000 --- src/channel.c 2023-03-07 17:42:34.808317572 +0000 *************** *** 109,115 **** size = (DWORD)todo; // If the pipe overflows while the job does not read the data, // WriteFile() will block forever. This abandons the write. ! memset(&ov, 0, sizeof(ov)); nwrite = 0; if (!WriteFile(h, buf + done, size, &nwrite, &ov)) { --- 109,115 ---- size = (DWORD)todo; // If the pipe overflows while the job does not read the data, // WriteFile() will block forever. This abandons the write. ! CLEAR_FIELD(ov); nwrite = 0; if (!WriteFile(h, buf + done, size, &nwrite, &ov)) { *** ../vim-9.0.1390/src/debugger.c 2023-02-21 14:27:34.512360384 +0000 --- src/debugger.c 2023-03-07 17:42:34.808317572 +0000 *************** *** 97,110 **** if (debug_oldval != NULL) { smsg(_("Oldval = \"%s\""), debug_oldval); ! vim_free(debug_oldval); ! debug_oldval = NULL; } if (debug_newval != NULL) { smsg(_("Newval = \"%s\""), debug_newval); ! vim_free(debug_newval); ! debug_newval = NULL; } sname = estack_sfile(ESTACK_NONE); if (sname != NULL) --- 97,108 ---- if (debug_oldval != NULL) { smsg(_("Oldval = \"%s\""), debug_oldval); ! VIM_CLEAR(debug_oldval); } if (debug_newval != NULL) { smsg(_("Newval = \"%s\""), debug_newval); ! VIM_CLEAR(debug_newval); } sname = estack_sfile(ESTACK_NONE); if (sname != NULL) *** ../vim-9.0.1390/src/diff.c 2023-03-07 17:13:47.305107775 +0000 --- src/diff.c 2023-03-07 17:42:34.808317572 +0000 *************** *** 726,735 **** clear_diffin(diffin_T *din) { if (din->din_fname == NULL) ! { ! vim_free(din->din_mmfile.ptr); ! din->din_mmfile.ptr = NULL; ! } else mch_remove(din->din_fname); } --- 726,732 ---- clear_diffin(diffin_T *din) { if (din->din_fname == NULL) ! VIM_CLEAR(din->din_mmfile.ptr); else mch_remove(din->din_fname); } *** ../vim-9.0.1390/src/evalfunc.c 2023-03-07 17:13:47.305107775 +0000 --- src/evalfunc.c 2023-03-07 17:42:34.808317572 +0000 *************** *** 4354,4360 **** rettv->v_type = VAR_STRING; cmdstr = vim_strsave(tv_get_string(&argvars[0])); ! memset(&eap, 0, sizeof(eap)); eap.cmd = cmdstr; eap.arg = cmdstr; eap.argt |= EX_NOSPC; --- 4354,4360 ---- rettv->v_type = VAR_STRING; cmdstr = vim_strsave(tv_get_string(&argvars[0])); ! CLEAR_FIELD(eap); eap.cmd = cmdstr; eap.arg = cmdstr; eap.argt |= EX_NOSPC; *** ../vim-9.0.1390/src/fileio.c 2023-03-05 13:12:28.492767233 +0000 --- src/fileio.c 2023-03-07 17:42:34.808317572 +0000 *************** *** 4382,4388 **** // file, not reset the syntax highlighting, clear marks, diff status, etc. // Force the fileformat and encoding to be the same. if (reload_options) ! memset(&ea, 0, sizeof(ea)); else prepped = prep_exarg(&ea, buf); --- 4382,4388 ---- // file, not reset the syntax highlighting, clear marks, diff status, etc. // Force the fileformat and encoding to be the same. if (reload_options) ! CLEAR_FIELD(ea); else prepped = prep_exarg(&ea, buf); *** ../vim-9.0.1390/src/gui_photon.c 2023-01-22 21:14:32.613863616 +0000 --- src/gui_photon.c 2023-03-07 17:42:34.808317572 +0000 *************** *** 1400,1406 **** char_u *open_text = NULL; flags = 0; ! memset(&file, 0, sizeof(file)); default_path = alloc(MAXPATHL + 1 + NAME_MAX + 1); if (default_path != NULL) --- 1400,1406 ---- char_u *open_text = NULL; flags = 0; ! CLEAR_FIELD(file); default_path = alloc(MAXPATHL + 1 + NAME_MAX + 1); if (default_path != NULL) *************** *** 1578,1585 **** PtModalCtrl_t modal_ctrl; PtDialogInfo_t di; ! memset(&di, 0, sizeof(di)); ! memset(&modal_ctrl, 0, sizeof(modal_ctrl)); n = 0; PtSetArg(&args[n++], Pt_ARG_GROUP_ROWS_COLS, 0, 0); --- 1578,1585 ---- PtModalCtrl_t modal_ctrl; PtDialogInfo_t di; ! CLEAR_FIELD(di); ! CLEAR_FIELD(modal_ctrl); n = 0; PtSetArg(&args[n++], Pt_ARG_GROUP_ROWS_COLS, 0, 0); *************** *** 1707,1713 **** { PhWindowEvent_t event; ! memset(&event, 0, sizeof (event)); event.event_f = Ph_WM_HIDE; event.event_state = Ph_WM_EVSTATE_HIDE; event.rid = PtWidgetRid(gui.vimWindow); --- 1707,1713 ---- { PhWindowEvent_t event; ! CLEAR_FIELD(event); event.event_f = Ph_WM_HIDE; event.event_state = Ph_WM_EVSTATE_HIDE; event.rid = PtWidgetRid(gui.vimWindow); *************** *** 1723,1729 **** { PhWindowEvent_t event; ! memset(&event, 0, sizeof (event)); event.event_f = Ph_WM_TOFRONT; event.event_state = Ph_WM_EVSTATE_FFRONT; event.rid = PtWidgetRid(gui.vimWindow); --- 1723,1729 ---- { PhWindowEvent_t event; ! CLEAR_FIELD(event); event.event_f = Ph_WM_TOFRONT; event.event_state = Ph_WM_EVSTATE_FFRONT; event.rid = PtWidgetRid(gui.vimWindow); *** ../vim-9.0.1390/src/gui_w32.c 2023-01-08 13:44:21.069352345 +0000 --- src/gui_w32.c 2023-03-07 17:42:34.812317571 +0000 *************** *** 8387,8393 **** TOOLINFOW *pti; RECT rect; ! pti = alloc(sizeof(TOOLINFOW)); if (pti == NULL) return; --- 8387,8393 ---- TOOLINFOW *pti; RECT rect; ! pti = ALLOC_ONE(TOOLINFOW); if (pti == NULL) return; *************** *** 8655,8661 **** // TODO: at the moment, this is just a copy of test_gui_mouse_event. // But, we could instead generate actual Win32 mouse event messages, ! // ie. to make it consistent wih test_gui_w32_sendevent_keyboard. static int test_gui_w32_sendevent_mouse(dict_T *args) { --- 8655,8661 ---- // TODO: at the moment, this is just a copy of test_gui_mouse_event. // But, we could instead generate actual Win32 mouse event messages, ! // ie. to make it consistent with test_gui_w32_sendevent_keyboard. static int test_gui_w32_sendevent_mouse(dict_T *args) { *** ../vim-9.0.1390/src/hardcopy.c 2023-02-20 12:16:33.332269406 +0000 --- src/hardcopy.c 2023-03-07 17:42:34.812317571 +0000 *************** *** 2721,2734 **** struct prt_ps_resource_S *res_cmap; int retval = FALSE; ! res_prolog = (struct prt_ps_resource_S *) ! alloc(sizeof(struct prt_ps_resource_S)); ! res_encoding = (struct prt_ps_resource_S *) ! alloc(sizeof(struct prt_ps_resource_S)); ! res_cidfont = (struct prt_ps_resource_S *) ! alloc(sizeof(struct prt_ps_resource_S)); ! res_cmap = (struct prt_ps_resource_S *) ! alloc(sizeof(struct prt_ps_resource_S)); if (res_prolog == NULL || res_encoding == NULL || res_cidfont == NULL || res_cmap == NULL) goto theend; --- 2721,2730 ---- struct prt_ps_resource_S *res_cmap; int retval = FALSE; ! res_prolog = ALLOC_ONE(struct prt_ps_resource_S); ! res_encoding = ALLOC_ONE(struct prt_ps_resource_S); ! res_cidfont = ALLOC_ONE(struct prt_ps_resource_S); ! res_cmap = ALLOC_ONE(struct prt_ps_resource_S); if (res_prolog == NULL || res_encoding == NULL || res_cidfont == NULL || res_cmap == NULL) goto theend; *** ../vim-9.0.1390/src/indent.c 2023-02-21 14:27:34.516360384 +0000 --- src/indent.c 2023-03-07 17:42:34.812317571 +0000 *************** *** 74,81 **** if (n <= 0 || n > TABSTOP_MAX) { semsg(_(e_invalid_argument_str), cp); ! vim_free(*array); ! *array = NULL; return FAIL; } (*array)[t++] = n; --- 74,80 ---- if (n <= 0 || n > TABSTOP_MAX) { semsg(_(e_invalid_argument_str), cp); ! VIM_CLEAR(*array); return FAIL; } (*array)[t++] = n; *** ../vim-9.0.1390/src/list.c 2023-01-14 12:32:24.215984102 +0000 --- src/list.c 2023-03-07 17:42:34.812317571 +0000 *************** *** 1687,1693 **** list_T *l = &sl->sl_list; int i; ! memset(sl, 0, sizeof(staticList10_T)); l->lv_first = &sl->sl_items[0]; l->lv_u.mat.lv_last = &sl->sl_items[9]; l->lv_refcount = DO_NOT_FREE_CNT; --- 1687,1693 ---- list_T *l = &sl->sl_list; int i; ! CLEAR_POINTER(sl); l->lv_first = &sl->sl_items[0]; l->lv_u.mat.lv_last = &sl->sl_items[9]; l->lv_refcount = DO_NOT_FREE_CNT; *** ../vim-9.0.1390/src/mbyte.c 2023-03-07 17:13:47.309107774 +0000 --- src/mbyte.c 2023-03-07 17:42:34.812317571 +0000 *************** *** 5634,5641 **** if (l->lv_len == 0) { // Clearing the table. ! vim_free(cw_table); ! cw_table = NULL; cw_table_size = 0; return; } --- 5634,5640 ---- if (l->lv_len == 0) { // Clearing the table. ! VIM_CLEAR(cw_table); cw_table_size = 0; return; } *** ../vim-9.0.1390/src/option.c 2023-03-04 20:47:32.304617857 +0000 --- src/option.c 2023-03-07 17:42:34.812317571 +0000 *************** *** 7147,7153 **** { buf->b_p_isk = save_p_isk; #ifdef FEAT_VARTABS ! if (p_vts && p_vts != empty_option && !buf->b_p_vts_array) (void)tabstop_set(p_vts, &buf->b_p_vts_array); else buf->b_p_vts_array = NULL; --- 7147,7153 ---- { buf->b_p_isk = save_p_isk; #ifdef FEAT_VARTABS ! if (p_vts && *p_vts != NUL && !buf->b_p_vts_array) (void)tabstop_set(p_vts, &buf->b_p_vts_array); else buf->b_p_vts_array = NULL; *************** *** 7163,7169 **** #ifdef FEAT_VARTABS buf->b_p_vts = vim_strsave(p_vts); COPY_OPT_SCTX(buf, BV_VTS); ! if (p_vts && p_vts != empty_option && !buf->b_p_vts_array) (void)tabstop_set(p_vts, &buf->b_p_vts_array); else buf->b_p_vts_array = NULL; --- 7163,7169 ---- #ifdef FEAT_VARTABS buf->b_p_vts = vim_strsave(p_vts); COPY_OPT_SCTX(buf, BV_VTS); ! if (p_vts && *p_vts != NUL && !buf->b_p_vts_array) (void)tabstop_set(p_vts, &buf->b_p_vts_array); else buf->b_p_vts_array = NULL; *** ../vim-9.0.1390/src/optionstr.c 2023-03-04 19:57:28.342671183 +0000 --- src/optionstr.c 2023-03-07 17:42:34.812317571 +0000 *************** *** 2714,2726 **** char_u *cp; if (!((*varp)[0]) || ((*varp)[0] == '0' && !((*varp)[1]))) ! { ! if (curbuf->b_p_vsts_array) ! { ! vim_free(curbuf->b_p_vsts_array); ! curbuf->b_p_vsts_array = 0; ! } ! } else { for (cp = *varp; *cp; ++cp) --- 2714,2720 ---- char_u *cp; if (!((*varp)[0]) || ((*varp)[0] == '0' && !((*varp)[1]))) ! VIM_CLEAR(curbuf->b_p_vsts_array); else { for (cp = *varp; *cp; ++cp) *************** *** 2755,2767 **** char_u *cp; if (!((*varp)[0]) || ((*varp)[0] == '0' && !((*varp)[1]))) ! { ! if (curbuf->b_p_vts_array) ! { ! vim_free(curbuf->b_p_vts_array); ! curbuf->b_p_vts_array = NULL; ! } ! } else { for (cp = *varp; *cp; ++cp) --- 2749,2755 ---- char_u *cp; if (!((*varp)[0]) || ((*varp)[0] == '0' && !((*varp)[1]))) ! VIM_CLEAR(curbuf->b_p_vts_array); else { for (cp = *varp; *cp; ++cp) *** ../vim-9.0.1390/src/os_qnx.c 2023-01-16 18:19:01.911301085 +0000 --- src/os_qnx.c 2023-03-07 17:42:34.812317571 +0000 *************** *** 24,30 **** #if defined(FEAT_GUI_PHOTON) PhChannelParms_t parms; ! memset(&parms, 0, sizeof(parms)); parms.flags = Ph_DYNAMIC_BUFFER; is_photon_available = (PhAttach(NULL, &parms) != NULL) ? TRUE : FALSE; --- 24,30 ---- #if defined(FEAT_GUI_PHOTON) PhChannelParms_t parms; ! CLEAR_FIELD(parms); parms.flags = Ph_DYNAMIC_BUFFER; is_photon_available = (PhAttach(NULL, &parms) != NULL) ? TRUE : FALSE; *************** *** 124,130 **** if (text_clip && vim_clip) { ! memset(clip_header, 0, sizeof(clip_header)); STRNCPY(clip_header[0].type, CLIP_TYPE_VIM, 8); clip_header[0].length = sizeof(vim_clip); --- 124,130 ---- if (text_clip && vim_clip) { ! CLEAR_FIELD(clip_header); STRNCPY(clip_header[0].type, CLIP_TYPE_VIM, 8); clip_header[0].length = sizeof(vim_clip); *** ../vim-9.0.1390/src/os_win32.c 2023-03-07 17:13:47.313107772 +0000 --- src/os_win32.c 2023-03-07 17:42:34.816317569 +0000 *************** *** 3764,3771 **** if (STRLEN(p) >= (size_t)len) { // long path name is too long, fall back to short one ! vim_free(p); ! p = NULL; } } if (p == NULL) --- 3764,3770 ---- if (STRLEN(p) >= (size_t)len) { // long path name is too long, fall back to short one ! VIM_CLEAR(p); } } if (p == NULL) *************** *** 8073,8080 **** if (pNtQueryEaFile(h, &iosb, ea, eainfo.EaSize, FALSE, NULL, 0, NULL, TRUE) != STATUS_SUCCESS) { ! vim_free(ea); ! ea = NULL; } } } --- 8072,8078 ---- if (pNtQueryEaFile(h, &iosb, ea, eainfo.EaSize, FALSE, NULL, 0, NULL, TRUE) != STATUS_SUCCESS) { ! VIM_CLEAR(ea); } } } *** ../vim-9.0.1390/src/popupwin.c 2023-03-07 17:13:47.313107772 +0000 --- src/popupwin.c 2023-03-07 17:42:34.816317569 +0000 *************** *** 3568,3575 **** if (wp->w_popup_mask == NULL || width == 0 || height == 0) { ! vim_free(wp->w_popup_mask_cells); ! wp->w_popup_mask_cells = NULL; return; } if (wp->w_popup_mask_cells != NULL --- 3568,3574 ---- if (wp->w_popup_mask == NULL || width == 0 || height == 0) { ! VIM_CLEAR(wp->w_popup_mask_cells); return; } if (wp->w_popup_mask_cells != NULL *** ../vim-9.0.1390/src/quickfix.c 2023-02-21 14:27:34.520360383 +0000 --- src/quickfix.c 2023-03-07 17:42:34.816317569 +0000 *************** *** 6213,6219 **** { char_u *p; ! vim_memset(args, 0, sizeof(*args)); args->regmatch.regprog = NULL; args->qf_title = vim_strsave(qf_cmdtitle(*eap->cmdlinep)); --- 6213,6219 ---- { char_u *p; ! CLEAR_POINTER(args); args->regmatch.regprog = NULL; args->qf_title = vim_strsave(qf_cmdtitle(*eap->cmdlinep)); *** ../vim-9.0.1390/src/search.c 2023-01-31 21:13:35.070100023 +0000 --- src/search.c 2023-03-07 17:42:34.816317569 +0000 *************** *** 3202,3208 **** proftime_T start; #endif ! vim_memset(stat, 0, sizeof(searchstat_T)); if (dirc == 0 && !recompute && !EMPTY_POS(lastpos)) { --- 3202,3208 ---- proftime_T start; #endif ! CLEAR_POINTER(stat); if (dirc == 0 && !recompute && !EMPTY_POS(lastpos)) { *** ../vim-9.0.1390/src/syntax.c 2023-03-07 17:13:47.317107770 +0000 --- src/syntax.c 2023-03-07 17:42:34.816317569 +0000 *************** *** 6287,6293 **** if (curwin->w_s == &curwin->w_buffer->b_s) { curwin->w_s = ALLOC_ONE(synblock_T); ! memset(curwin->w_s, 0, sizeof(synblock_T)); hash_init(&curwin->w_s->b_keywtab); hash_init(&curwin->w_s->b_keywtab_ic); #ifdef FEAT_SPELL --- 6287,6293 ---- if (curwin->w_s == &curwin->w_buffer->b_s) { curwin->w_s = ALLOC_ONE(synblock_T); ! CLEAR_POINTER(curwin->w_s); hash_init(&curwin->w_s->b_keywtab); hash_init(&curwin->w_s->b_keywtab_ic); #ifdef FEAT_SPELL *** ../vim-9.0.1390/src/textprop.c 2023-03-07 17:13:47.317107770 +0000 --- src/textprop.c 2023-03-07 17:42:34.816317569 +0000 *************** *** 1718,1725 **** if (ii < gap->ga_len) { char_u **p = ((char_u **)gap->ga_data) + ii; ! vim_free(*p); ! *p = NULL; did_remove_text = TRUE; } } --- 1718,1724 ---- if (ii < gap->ga_len) { char_u **p = ((char_u **)gap->ga_data) + ii; ! VIM_CLEAR(*p); did_remove_text = TRUE; } } *** ../vim-9.0.1390/src/userfunc.c 2023-03-07 17:13:47.317107770 +0000 --- src/userfunc.c 2023-03-07 17:42:34.816317569 +0000 *************** *** 5155,5169 **** fudi.fd_di = dictitem_alloc(fudi.fd_newkey); if (fudi.fd_di == NULL) { ! vim_free(fp); ! fp = NULL; goto erret; } if (dict_add(fudi.fd_dict, fudi.fd_di) == FAIL) { vim_free(fudi.fd_di); ! vim_free(fp); ! fp = NULL; goto erret; } } --- 5155,5167 ---- fudi.fd_di = dictitem_alloc(fudi.fd_newkey); if (fudi.fd_di == NULL) { ! VIM_CLEAR(fp); goto erret; } if (dict_add(fudi.fd_dict, fudi.fd_di) == FAIL) { vim_free(fudi.fd_di); ! VIM_CLEAR(fp); goto erret; } } *************** *** 5292,5301 **** clear_type_list(&fp->uf_type_list); } if (free_fp) ! { ! vim_free(fp); ! fp = NULL; ! } ret_free: ga_clear_strings(&argtypes); vim_free(fudi.fd_newkey); --- 5290,5296 ---- clear_type_list(&fp->uf_type_list); } if (free_fp) ! VIM_CLEAR(fp); ret_free: ga_clear_strings(&argtypes); vim_free(fudi.fd_newkey); *** ../vim-9.0.1390/src/version.c 2023-03-07 17:13:47.321107768 +0000 --- src/version.c 2023-03-07 17:44:26.100266680 +0000 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 1391, /**/ -- "Marriage is a wonderful institution... but who wants to live in an institution?" - Groucho Marx /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///