]> granicus.if.org Git - vim/commitdiff
patch 9.0.1391: "clear" macros are not always used v9.0.1391
authorYegappan Lakshmanan <yegappan@yahoo.com>
Tue, 7 Mar 2023 17:45:11 +0000 (17:45 +0000)
committerBram Moolenaar <Bram@vim.org>
Tue, 7 Mar 2023 17:45:11 +0000 (17:45 +0000)
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)

23 files changed:
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
src/version.c

index ff35729fb9299b90529da59ce3c315970266af54..f6c161081dd9ac1d61bd6792a4d0f7ff3a13193c 100644 (file)
@@ -2375,8 +2375,7 @@ free_buf_options(
     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_nopaste);
     VIM_CLEAR(buf->b_p_vsts_array);
     clear_string_option(&buf->b_p_vts);
     VIM_CLEAR(buf->b_p_vts_array);
index 33605d4b6ad77ec17404d64154818988a2cfd5d8..97eb5db99c0bb3d6f596edc6a4bd9d02ab8d7c95 100644 (file)
@@ -109,7 +109,7 @@ fd_write(sock_T fd, char *buf, size_t len)
            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));
+       CLEAR_FIELD(ov);
        nwrite = 0;
        if (!WriteFile(h, buf + done, size, &nwrite, &ov))
        {
index b158ecdd7095d32e6773c892b264950e77aa542d..a04a07836121a08c87f4e01959288bd530297e2e 100644 (file)
@@ -97,14 +97,12 @@ do_debug(char_u *cmd)
     if (debug_oldval != NULL)
     {
        smsg(_("Oldval = \"%s\""), debug_oldval);
-       vim_free(debug_oldval);
-       debug_oldval = NULL;
+       VIM_CLEAR(debug_oldval);
     }
     if (debug_newval != NULL)
     {
        smsg(_("Newval = \"%s\""), debug_newval);
-       vim_free(debug_newval);
-       debug_newval = NULL;
+       VIM_CLEAR(debug_newval);
     }
     sname = estack_sfile(ESTACK_NONE);
     if (sname != NULL)
index 6c13d2ac4dc9bc8a2193dc234e3502faf7adf75c..a46f0bf81e7fb632b6bec590d3955287b29c14d0 100644 (file)
@@ -726,10 +726,7 @@ diff_redraw(
 clear_diffin(diffin_T *din)
 {
     if (din->din_fname == NULL)
-    {
-       vim_free(din->din_mmfile.ptr);
-       din->din_mmfile.ptr = NULL;
-    }
+       VIM_CLEAR(din->din_mmfile.ptr);
     else
        mch_remove(din->din_fname);
 }
index 135cb58894f4dc3d80e1ab2487630db2a192093f..0f266dceedec727c54274a15694e0a0b02a8154c 100644 (file)
@@ -4354,7 +4354,7 @@ f_expandcmd(typval_T *argvars, typval_T *rettv)
     rettv->v_type = VAR_STRING;
     cmdstr = vim_strsave(tv_get_string(&argvars[0]));
 
-    memset(&eap, 0, sizeof(eap));
+    CLEAR_FIELD(eap);
     eap.cmd = cmdstr;
     eap.arg = cmdstr;
     eap.argt |= EX_NOSPC;
index 5a2e388e4a5e1768c052789de443f7b304a77c93..19664201e9f75c63644d907f1898340ac2d95f5e 100644 (file)
@@ -4382,7 +4382,7 @@ buf_reload(buf_T *buf, int orig_mode, int reload_options)
     // 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));
+       CLEAR_FIELD(ea);
     else
        prepped = prep_exarg(&ea, buf);
 
index a17b4f5d03091bfc7e397035cd3d8637897e228b..0eb1282e06c2cacbf57a80c24b0c1abeaacd3ec1 100644 (file)
@@ -1400,7 +1400,7 @@ gui_mch_browse(
     char_u  *open_text = NULL;
 
     flags = 0;
-    memset(&file, 0, sizeof(file));
+    CLEAR_FIELD(file);
 
     default_path = alloc(MAXPATHL + 1 + NAME_MAX + 1);
     if (default_path != NULL)
@@ -1578,8 +1578,8 @@ gui_mch_dialog(
            PtModalCtrl_t modal_ctrl;
            PtDialogInfo_t di;
 
-           memset(&di, 0, sizeof(di));
-           memset(&modal_ctrl, 0, sizeof(modal_ctrl));
+           CLEAR_FIELD(di);
+           CLEAR_FIELD(modal_ctrl);
 
            n = 0;
            PtSetArg(&args[n++], Pt_ARG_GROUP_ROWS_COLS, 0, 0);
@@ -1707,7 +1707,7 @@ gui_mch_iconify(void)
 {
     PhWindowEvent_t event;
 
-    memset(&event, 0, sizeof (event));
+    CLEAR_FIELD(event);
     event.event_f = Ph_WM_HIDE;
     event.event_state = Ph_WM_EVSTATE_HIDE;
     event.rid = PtWidgetRid(gui.vimWindow);
@@ -1723,7 +1723,7 @@ gui_mch_set_foreground(void)
 {
     PhWindowEvent_t event;
 
-    memset(&event, 0, sizeof (event));
+    CLEAR_FIELD(event);
     event.event_f = Ph_WM_TOFRONT;
     event.event_state = Ph_WM_EVSTATE_FFRONT;
     event.rid = PtWidgetRid(gui.vimWindow);
index 206645a4f181ec48a207ca83d04ed2c8d4321899..7a1203266e54fd615e37819c78887d31291d3d5e 100644 (file)
@@ -8387,7 +8387,7 @@ make_tooltip(BalloonEval *beval, char *text, POINT pt)
     TOOLINFOW  *pti;
     RECT       rect;
 
-    pti = alloc(sizeof(TOOLINFOW));
+    pti = ALLOC_ONE(TOOLINFOW);
     if (pti == NULL)
        return;
 
@@ -8655,7 +8655,7 @@ netbeans_draw_multisign_indicator(int row)
 
 // 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.
+// ie. to make it consistent with test_gui_w32_sendevent_keyboard.
     static int
 test_gui_w32_sendevent_mouse(dict_T *args)
 {
index f6be017c33417f765b4e951bac3eb1a4debf4780..e91a7dc2d7362b5cb5bb2a9907f6585aa323a96d 100644 (file)
@@ -2721,14 +2721,10 @@ mch_print_begin(prt_settings_T *psettings)
     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));
+    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;
index be4d56359e22eda724cf27b0aedadd1b9cba6dfa..3c38b4ec373055c53d9ef57eb83e07dfd2f21074 100644 (file)
@@ -74,8 +74,7 @@ tabstop_set(char_u *var, int **array)
        if (n <= 0 || n > TABSTOP_MAX)
        {
            semsg(_(e_invalid_argument_str), cp);
-           vim_free(*array);
-           *array = NULL;
+           VIM_CLEAR(*array);
            return FAIL;
        }
        (*array)[t++] = n;
index 71184547ef1cc14b2c190b22ef459eaa4e74fc11..ae9e3e957a22900548fe1f5c123da5dfa471de3d 100644 (file)
@@ -1687,7 +1687,7 @@ init_static_list(staticList10_T *sl)
     list_T  *l = &sl->sl_list;
     int            i;
 
-    memset(sl, 0, sizeof(staticList10_T));
+    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;
index 5e6aed02bbdee298cbccb62933ad440fe9bb9861..a9603cbf2a90a711c3ccb72433c31ea2e26bcaee 100644 (file)
@@ -5634,8 +5634,7 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
     if (l->lv_len == 0)
     {
        // Clearing the table.
-       vim_free(cw_table);
-       cw_table = NULL;
+       VIM_CLEAR(cw_table);
        cw_table_size = 0;
        return;
     }
index f47b51c8746722f7370d72c49260e488ab735754..870182b90cea06d2061b4fd8cb2e447a9113eb58 100644 (file)
@@ -7147,7 +7147,7 @@ buf_copy_options(buf_T *buf, int flags)
            {
                buf->b_p_isk = save_p_isk;
 #ifdef FEAT_VARTABS
-               if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
+               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,7 +7163,7 @@ buf_copy_options(buf_T *buf, int flags)
 #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)
+               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;
index 0389ed0306835e974f493192cb84ef4617b6265a..f88325cec98ab7e56c739beaefe0f6e922394ff4 100644 (file)
@@ -2714,13 +2714,7 @@ did_set_varsofttabstop(optset_T *args)
     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;
-       }
-    }
+       VIM_CLEAR(curbuf->b_p_vsts_array);
     else
     {
        for (cp = *varp; *cp; ++cp)
@@ -2755,13 +2749,7 @@ did_set_vartabstop(optset_T *args)
     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;
-       }
-    }
+       VIM_CLEAR(curbuf->b_p_vts_array);
     else
     {
        for (cp = *varp; *cp; ++cp)
index 4a7b363f1353cb6fcd14d2c8c98853d22b99ba5e..d3ebb203700e274d24594596e3def5d635ee1a49 100644 (file)
@@ -24,7 +24,7 @@ void qnx_init(void)
 #if defined(FEAT_GUI_PHOTON)
     PhChannelParms_t parms;
 
-    memset(&parms, 0, sizeof(parms));
+    CLEAR_FIELD(parms);
     parms.flags = Ph_DYNAMIC_BUFFER;
 
     is_photon_available = (PhAttach(NULL, &parms) != NULL) ? TRUE : FALSE;
@@ -124,7 +124,7 @@ clip_mch_set_selection(Clipboard_T *cbd)
 
        if (text_clip && vim_clip)
        {
-           memset(clip_header, 0, sizeof(clip_header));
+           CLEAR_FIELD(clip_header);
 
            STRNCPY(clip_header[0].type, CLIP_TYPE_VIM, 8);
            clip_header[0].length = sizeof(vim_clip);
index b519bf0ecac5279299d2531032d7a2d52b202219..c43a31afcb640e9ee09119c05c86cbb9aafc104d 100644 (file)
@@ -3764,8 +3764,7 @@ mch_dirname(
        if (STRLEN(p) >= (size_t)len)
        {
            // long path name is too long, fall back to short one
-           vim_free(p);
-           p = NULL;
+           VIM_CLEAR(p);
        }
     }
     if (p == NULL)
@@ -8073,8 +8072,7 @@ copy_extattr(char_u *from, char_u *to)
            if (pNtQueryEaFile(h, &iosb, ea, eainfo.EaSize, FALSE,
                        NULL, 0, NULL, TRUE) != STATUS_SUCCESS)
            {
-               vim_free(ea);
-               ea = NULL;
+               VIM_CLEAR(ea);
            }
        }
     }
index c34ee9fe325e2810c18ed7103c74b1f1f3cbfaaf..a0d33fd0bb56fcfd967be8c519a2a2926c8f2deb 100644 (file)
@@ -3568,8 +3568,7 @@ popup_update_mask(win_T *wp, int width, int height)
 
     if (wp->w_popup_mask == NULL || width == 0 || height == 0)
     {
-       vim_free(wp->w_popup_mask_cells);
-       wp->w_popup_mask_cells = NULL;
+       VIM_CLEAR(wp->w_popup_mask_cells);
        return;
     }
     if (wp->w_popup_mask_cells != NULL
index 63dd54167041daf94fc9638483379144a838bd57..13292e2f7515c6ba92ffb343f0659564e5ea1ed9 100644 (file)
@@ -6213,7 +6213,7 @@ vgr_process_args(
 {
     char_u     *p;
 
-    vim_memset(args, 0, sizeof(*args));
+    CLEAR_POINTER(args);
 
     args->regmatch.regprog = NULL;
     args->qf_title = vim_strsave(qf_cmdtitle(*eap->cmdlinep));
index 1e4464b0c603ce64b66d929eeadc09324f2620e4..74ca8fefb2c56288da94c62f9f56ffc26538609c 100644 (file)
@@ -3202,7 +3202,7 @@ update_search_stat(
     proftime_T  start;
 #endif
 
-    vim_memset(stat, 0, sizeof(searchstat_T));
+    CLEAR_POINTER(stat);
 
     if (dirc == 0 && !recompute && !EMPTY_POS(lastpos))
     {
index a4fa249fa375580742729a0d84462da6b1a57c75..4e3595690ced32c905dc0bfda0567ff0775e0928 100644 (file)
@@ -6287,7 +6287,7 @@ ex_ownsyntax(exarg_T *eap)
     if (curwin->w_s == &curwin->w_buffer->b_s)
     {
        curwin->w_s = ALLOC_ONE(synblock_T);
-       memset(curwin->w_s, 0, sizeof(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
index bead1463361502886605d12b149888d1341e4592..c6464fc47775997ce85667ac370874e1c6d5105f 100644 (file)
@@ -1718,8 +1718,7 @@ f_prop_remove(typval_T *argvars, typval_T *rettv)
                        if (ii < gap->ga_len)
                        {
                            char_u **p = ((char_u **)gap->ga_data) + ii;
-                           vim_free(*p);
-                           *p = NULL;
+                           VIM_CLEAR(*p);
                            did_remove_text = TRUE;
                        }
                    }
index 878e07f91fea96234d03ff0297cb0a328ffb4399..3885f67ad2c6660fbea753ed8046e5493614924c 100644 (file)
@@ -5155,15 +5155,13 @@ define_function(
                fudi.fd_di = dictitem_alloc(fudi.fd_newkey);
                if (fudi.fd_di == NULL)
                {
-                   vim_free(fp);
-                   fp = NULL;
+                   VIM_CLEAR(fp);
                    goto erret;
                }
                if (dict_add(fudi.fd_dict, fudi.fd_di) == FAIL)
                {
                    vim_free(fudi.fd_di);
-                   vim_free(fp);
-                   fp = NULL;
+                   VIM_CLEAR(fp);
                    goto erret;
                }
            }
@@ -5292,10 +5290,7 @@ errret_2:
        clear_type_list(&fp->uf_type_list);
     }
     if (free_fp)
-    {
-       vim_free(fp);
-       fp = NULL;
-    }
+       VIM_CLEAR(fp);
 ret_free:
     ga_clear_strings(&argtypes);
     vim_free(fudi.fd_newkey);
index 326379cac1f08c764823891279bfdc7d6f7e27c5..0270abdc1ebca2dbfb2cdd7d9a693afef5d4139f 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1391,
 /**/
     1390,
 /**/