Patch 8.2.2922
Problem: Computing array length is done in various ways.
Solution: Use ARRAY_LENGTH everywhere. (Ken Takata, closes #8305)
Files: src/arabic.c, src/blowfish.c, src/cindent.c, src/cmdexpand.c,
src/cmdhist.c, src/dosinst.c, src/eval.c, src/evalfunc.c,
src/ex_docmd.c, src/fileio.c, src/gui_athena.c, src/gui_gtk_x11.c,
src/gui_haiku.cc, src/gui_photon.c, src/gui_w32.c,
src/gui_xmebw.c, src/hardcopy.c, src/help.c, src/highlight.c,
src/if_mzsch.c, src/macros.h, src/main.c, src/map.c, src/mbyte.c,
src/memline.c, src/menu.c, src/misc2.c, src/normal.c, src/ops.c,
src/option.c, src/optiondefs.h, src/os_win32.c, src/popupwin.c,
src/quickfix.c, src/regexp.c, src/screen.c, src/search.c,
src/syntax.c, src/term.c, src/terminal.c, src/time.c,
src/usercmd.c, src/version.c
*** ../vim-8.2.2921/src/arabic.c 2019-03-30 18:22:15.000000000 +0100
--- src/arabic.c 2021-06-02 13:22:19.115869325 +0200
***************
*** 163,170 ****
#define a_BYTE_ORDER_MARK 0xfeff
- #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
-
/*
* Find the struct achar pointer to the given Arabic char.
* Returns NULL if not found.
--- 163,168 ----
***************
*** 175,181 ****
int h, m, l;
// using binary search to find c
! h = ARRAY_SIZE(achars);
l = 0;
while (l < h)
{
--- 173,179 ----
int h, m, l;
// using binary search to find c
! h = ARRAY_LENGTH(achars);
l = 0;
while (l < h)
{
*** ../vim-8.2.2921/src/blowfish.c 2020-04-12 19:37:13.506297291 +0200
--- src/blowfish.c 2021-06-02 13:22:19.115869325 +0200
***************
*** 23,30 ****
#if defined(FEAT_CRYPT) || defined(PROTO)
- #define ARRAY_LENGTH(A) (sizeof(A)/sizeof(A[0]))
-
#define BF_BLOCK 8
#define BF_BLOCK_MASK 7
#define BF_MAX_CFB_LEN (8 * BF_BLOCK)
--- 23,28 ----
*** ../vim-8.2.2921/src/cindent.c 2020-12-18 19:49:52.337571884 +0100
--- src/cindent.c 2021-06-02 13:22:19.115869325 +0200
***************
*** 718,724 ****
{
int i, l;
! for (i = 0; i < (int)(sizeof(skip) / sizeof(char *)); ++i)
{
l = (int)strlen(skip[i]);
if (cin_starts_with(s, skip[i]))
--- 718,724 ----
{
int i, l;
! for (i = 0; i < (int)ARRAY_LENGTH(skip); ++i)
{
l = (int)strlen(skip[i]);
if (cin_starts_with(s, skip[i]))
*** ../vim-8.2.2921/src/cmdexpand.c 2021-03-28 15:29:39.642657793 +0200
--- src/cmdexpand.c 2021-06-02 13:22:19.115869325 +0200
***************
*** 2155,2161 ****
// Find a context in the table and call the ExpandGeneric() with the
// right function to do the expansion.
ret = FAIL;
! for (i = 0; i < (int)(sizeof(tab) / sizeof(struct expgen)); ++i)
if (xp->xp_context == tab[i].context)
{
if (tab[i].ic)
--- 2155,2161 ----
// Find a context in the table and call the ExpandGeneric() with the
// right function to do the expansion.
ret = FAIL;
! for (i = 0; i < (int)ARRAY_LENGTH(tab); ++i)
if (xp->xp_context == tab[i].context)
{
if (tab[i].ic)
*** ../vim-8.2.2921/src/cmdhist.c 2020-10-24 20:49:37.490683063 +0200
--- src/cmdhist.c 2021-06-02 13:22:19.115869325 +0200
***************
*** 98,104 ****
static char_u compl[2] = { NUL, NUL };
char *short_names = ":=@>?/";
int short_names_count = (int)STRLEN(short_names);
! int history_name_count = sizeof(history_names) / sizeof(char *) - 1;
if (idx < short_names_count)
{
--- 98,104 ----
static char_u compl[2] = { NUL, NUL };
char *short_names = ":=@>?/";
int short_names_count = (int)STRLEN(short_names);
! int history_name_count = ARRAY_LENGTH(history_names) - 1;
if (idx < short_names_count)
{
*** ../vim-8.2.2921/src/dosinst.c 2020-03-23 22:17:08.535747168 +0100
--- src/dosinst.c 2021-06-02 13:22:19.115869325 +0200
***************
*** 59,65 ****
struct choice choices[30]; // choices the user can make
int choice_count = 0; // number of choices available
! #define TABLE_SIZE(s) (int)(sizeof(s) / sizeof(*s))
enum
{
--- 59,65 ----
struct choice choices[30]; // choices the user can make
int choice_count = 0; // number of choices available
! #define TABLE_SIZE(s) (int)ARRAYSIZE(s)
enum
{
***************
*** 1527,1534 ****
"*\\OpenWithList\\gvim.exe",
};
! for (i = 0; ERROR_SUCCESS == lRet
! && i < sizeof(openwith) / sizeof(openwith[0]); i++)
lRet = reg_create_key_and_value(hRootKey, openwith[i], NULL, "", flag);
}
--- 1527,1533 ----
"*\\OpenWithList\\gvim.exe",
};
! for (i = 0; ERROR_SUCCESS == lRet && i < ARRAYSIZE(openwith); i++)
lRet = reg_create_key_and_value(hRootKey, openwith[i], NULL, "", flag);
}
*** ../vim-8.2.2921/src/eval.c 2021-06-01 21:21:51.918500942 +0200
--- src/eval.c 2021-06-02 13:22:19.115869325 +0200
***************
*** 125,131 ****
static void
sortFunctions(void)
{
! int funcCnt = (int)(sizeof(functions) / sizeof(struct fst)) - 1;
qsort(functions, (size_t)funcCnt, sizeof(struct fst), compare_func_name);
}
--- 125,131 ----
static void
sortFunctions(void)
{
! int funcCnt = (int)ARRAY_LENGTH(functions) - 1;
qsort(functions, (size_t)funcCnt, sizeof(struct fst), compare_func_name);
}
*** ../vim-8.2.2921/src/evalfunc.c 2021-05-18 21:46:27.712961269 +0200
--- src/evalfunc.c 2021-06-02 13:22:19.119869316 +0200
***************
*** 1877,1883 ****
return name;
}
}
! if (++intidx < (int)(sizeof(global_functions) / sizeof(funcentry_T)))
{
STRCPY(IObuff, global_functions[intidx].f_name);
STRCAT(IObuff, "(");
--- 1877,1883 ----
return name;
}
}
! if (++intidx < (int)ARRAY_LENGTH(global_functions))
{
STRCPY(IObuff, global_functions[intidx].f_name);
STRCAT(IObuff, "(");
***************
*** 1923,1929 ****
int cmp;
int x;
! last = (int)(sizeof(global_functions) / sizeof(funcentry_T)) - 1;
// Find the function name in the table. Binary search.
while (first <= last)
--- 1923,1929 ----
int cmp;
int x;
! last = (int)ARRAY_LENGTH(global_functions) - 1;
// Find the function name in the table. Binary search.
while (first <= last)
*** ../vim-8.2.2921/src/ex_docmd.c 2021-05-29 14:30:40.192274126 +0200
--- src/ex_docmd.c 2021-06-02 13:22:19.119869316 +0200
***************
*** 3735,3741 ****
if (VIM_ISDIGIT(*cmd))
p = skipwhite(skipdigits(cmd + 1));
! for (i = 0; i < (int)(sizeof(cmdmods) / sizeof(struct cmdmod)); ++i)
{
for (j = 0; p[j] != NUL; ++j)
if (p[j] != cmdmods[i].name[j])
--- 3735,3741 ----
if (VIM_ISDIGIT(*cmd))
p = skipwhite(skipdigits(cmd + 1));
! for (i = 0; i < (int)ARRAY_LENGTH(cmdmods); ++i)
{
for (j = 0; p[j] != NUL; ++j)
if (p[j] != cmdmods[i].name[j])
***************
*** 3762,3768 ****
char_u *p;
// Check command modifiers.
! for (i = 0; i < (int)(sizeof(cmdmods) / sizeof(struct cmdmod)); ++i)
{
for (j = 0; name[j] != NUL; ++j)
if (name[j] != cmdmods[i].name[j])
--- 3762,3768 ----
char_u *p;
// Check command modifiers.
! for (i = 0; i < (int)ARRAY_LENGTH(cmdmods); ++i)
{
for (j = 0; name[j] != NUL; ++j)
if (name[j] != cmdmods[i].name[j])
***************
*** 8732,8738 ****
#endif
};
! for (i = 0; i < (int)(sizeof(spec_str) / sizeof(char *)); ++i)
{
len = (int)STRLEN(spec_str[i]);
if (STRNCMP(src, spec_str[i], len) == 0)
--- 8732,8738 ----
#endif
};
! for (i = 0; i < (int)ARRAY_LENGTH(spec_str); ++i)
{
len = (int)STRLEN(spec_str[i]);
if (STRNCMP(src, spec_str[i], len) == 0)
*** ../vim-8.2.2921/src/fileio.c 2021-05-03 19:49:48.447891682 +0200
--- src/fileio.c 2021-06-02 13:22:19.119869316 +0200
***************
*** 5073,5079 ****
/*
* Try the entries in TEMPDIRNAMES to create the temp directory.
*/
! for (i = 0; i < (int)(sizeof(tempdirs) / sizeof(char *)); ++i)
{
# ifndef HAVE_MKDTEMP
size_t itmplen;
--- 5073,5079 ----
/*
* Try the entries in TEMPDIRNAMES to create the temp directory.
*/
! for (i = 0; i < (int)ARRAY_LENGTH(tempdirs); ++i)
{
# ifndef HAVE_MKDTEMP
size_t itmplen;
*** ../vim-8.2.2921/src/gui_athena.c 2020-07-17 20:43:37.284617059 +0200
--- src/gui_athena.c 2021-06-02 13:22:19.119869316 +0200
***************
*** 469,475 ****
if (menu->icon_builtin || gui_find_bitmap(menu->name, buf, "xpm") == FAIL)
{
if (menu->iconidx >= 0 && menu->iconidx
! < (int)(sizeof(built_in_pixmaps) / sizeof(built_in_pixmaps[0])))
xpm = built_in_pixmaps[menu->iconidx];
else
xpm = tb_blank_xpm;
--- 469,475 ----
if (menu->icon_builtin || gui_find_bitmap(menu->name, buf, "xpm") == FAIL)
{
if (menu->iconidx >= 0 && menu->iconidx
! < (int)ARRAY_LENGTH(built_in_pixmaps))
xpm = built_in_pixmaps[menu->iconidx];
else
xpm = tb_blank_xpm;
*** ../vim-8.2.2921/src/gui_gtk_x11.c 2021-03-20 12:36:43.104626123 +0100
--- src/gui_gtk_x11.c 2021-06-02 13:22:19.119869316 +0200
***************
*** 134,140 ****
{"TEXT", 0, TARGET_TEXT},
{"STRING", 0, TARGET_STRING}
};
! #define N_SELECTION_TARGETS (sizeof(selection_targets) / sizeof(selection_targets[0]))
#ifdef FEAT_DND
/*
--- 134,140 ----
{"TEXT", 0, TARGET_TEXT},
{"STRING", 0, TARGET_STRING}
};
! #define N_SELECTION_TARGETS ARRAY_LENGTH(selection_targets)
#ifdef FEAT_DND
/*
***************
*** 149,155 ****
{"STRING", 0, TARGET_STRING},
{"text/plain", 0, TARGET_TEXT_PLAIN}
};
! # define N_DND_TARGETS (sizeof(dnd_targets) / sizeof(dnd_targets[0]))
#endif
--- 149,155 ----
{"STRING", 0, TARGET_STRING},
{"text/plain", 0, TARGET_TEXT_PLAIN}
};
! # define N_DND_TARGETS ARRAY_LENGTH(dnd_targets)
#endif
***************
*** 6853,6859 ****
else
id &= ~1; // they are always even (why?)
}
! else if (shape < (int)(sizeof(mshape_ids) / sizeof(int)))
id = mshape_ids[shape];
else
return;
--- 6853,6859 ----
else
id &= ~1; // they are always even (why?)
}
! else if (shape < (int)ARRAY_LENGTH(mshape_ids))
id = mshape_ids[shape];
else
return;
*** ../vim-8.2.2921/src/gui_haiku.cc 2020-12-18 19:49:52.341571870 +0100
--- src/gui_haiku.cc 2021-06-02 13:22:19.119869316 +0200
***************
*** 638,644 ****
{0, 0, 0}
};
! #define NUM_SPECIAL_KEYS (sizeof(special_keys)/sizeof(special_keys[0]))
// ---------------- VimApp ----------------
--- 638,644 ----
{0, 0, 0}
};
! #define NUM_SPECIAL_KEYS ARRAY_LENGTH(special_keys)
// ---------------- VimApp ----------------
*** ../vim-8.2.2921/src/gui_photon.c 2020-08-01 13:10:04.586539542 +0200
--- src/gui_photon.c 2021-06-02 13:22:19.119869316 +0200
***************
*** 34,40 ****
# define PhImage_t int
#endif
- #define ARRAY_LENGTH(a) (sizeof(a) / sizeof(a[0]))
#define RGB(r, g, b) PgRGB(r, g, b)
#define EVENT_BUFFER_SIZE sizeof(PhEvent_t) + 1000
--- 34,39 ----
*** ../vim-8.2.2921/src/gui_w32.c 2020-11-18 15:21:46.661732137 +0100
--- src/gui_w32.c 2021-06-02 13:22:19.119869316 +0200
***************
*** 1627,1633 ****
/*
* Try to look up a system colour.
*/
! for (i = 0; i < sizeof(sys_table) / sizeof(sys_table[0]); i++)
if (STRICMP(name, sys_table[i].name) == 0)
return GetSysColor(sys_table[i].color);
--- 1627,1633 ----
/*
* Try to look up a system colour.
*/
! for (i = 0; i < ARRAY_LENGTH(sys_table); i++)
if (STRICMP(name, sys_table[i].name) == 0)
return GetSysColor(sys_table[i].color);
***************
*** 5077,5083 ****
/*
* Parse the GUI related command-line arguments. Any arguments used are
* deleted from argv, and *argc is decremented accordingly. This is called
! * when vim is started, whether or not the GUI has been started.
*/
void
gui_mch_prepare(int *argc, char **argv)
--- 5077,5083 ----
/*
* Parse the GUI related command-line arguments. Any arguments used are
* deleted from argv, and *argc is decremented accordingly. This is called
! * when Vim is started, whether or not the GUI has been started.
*/
void
gui_mch_prepare(int *argc, char **argv)
*** ../vim-8.2.2921/src/gui_xmebw.c 2021-01-04 10:47:21.698153964 +0100
--- src/gui_xmebw.c 2021-06-02 13:22:19.119869316 +0200
***************
*** 455,461 ****
attr.valuemask = XpmColorSymbols | XpmCloseness | XpmColorKey;
attr.closeness = 65535; // accuracy isn't crucial
attr.colorsymbols = color;
! attr.numsymbols = sizeof(color) / sizeof(color[0]);
attr.color_key = XPM_MONO;
status = XpmCreatePixmapFromData(dpy, root, data, &pix, &mask, &attr);
--- 455,461 ----
attr.valuemask = XpmColorSymbols | XpmCloseness | XpmColorKey;
attr.closeness = 65535; // accuracy isn't crucial
attr.colorsymbols = color;
! attr.numsymbols = ARRAY_LENGTH(color);
attr.color_key = XPM_MONO;
status = XpmCreatePixmapFromData(dpy, root, data, &pix, &mask, &attr);
*** ../vim-8.2.2921/src/hardcopy.c 2020-04-12 19:37:13.514297270 +0200
--- src/hardcopy.c 2021-06-02 13:22:19.123869308 +0200
***************
*** 972,979 ****
*
http://www.adobe.com
*/
- #define NUM_ELEMENTS(arr) (sizeof(arr)/sizeof((arr)[0]))
-
#define PRT_PS_DEFAULT_DPI (72) // Default user space resolution
#define PRT_PS_DEFAULT_FONTSIZE (10)
#define PRT_PS_DEFAULT_BUFFER_SIZE (80)
--- 972,977 ----
***************
*** 985,991 ****
float height;
};
! #define PRT_MEDIASIZE_LEN (sizeof(prt_mediasize) / sizeof(struct prt_mediasize_S))
static struct prt_mediasize_S prt_mediasize[] =
{
--- 983,989 ----
float height;
};
! #define PRT_MEDIASIZE_LEN ARRAY_LENGTH(prt_mediasize)
static struct prt_mediasize_S prt_mediasize[] =
{
***************
*** 1210,1242 ****
static struct prt_ps_mbfont_S prt_ps_mbfonts[] =
{
{
! NUM_ELEMENTS(j_encodings),
j_encodings,
! NUM_ELEMENTS(j_charsets),
j_charsets,
"jis_roman",
"JIS_X_1983"
},
{
! NUM_ELEMENTS(sc_encodings),
sc_encodings,
! NUM_ELEMENTS(sc_charsets),
sc_charsets,
"gb_roman",
"GB_2312-80"
},
{
! NUM_ELEMENTS(tc_encodings),
tc_encodings,
! NUM_ELEMENTS(tc_charsets),
tc_charsets,
"cns_roman",
"BIG5"
},
{
! NUM_ELEMENTS(k_encodings),
k_encodings,
! NUM_ELEMENTS(k_charsets),
k_charsets,
"ks_roman",
"KS_X_1992"
--- 1208,1240 ----
static struct prt_ps_mbfont_S prt_ps_mbfonts[] =
{
{
! ARRAY_LENGTH(j_encodings),
j_encodings,
! ARRAY_LENGTH(j_charsets),
j_charsets,
"jis_roman",
"JIS_X_1983"
},
{
! ARRAY_LENGTH(sc_encodings),
sc_encodings,
! ARRAY_LENGTH(sc_charsets),
sc_charsets,
"gb_roman",
"GB_2312-80"
},
{
! ARRAY_LENGTH(tc_encodings),
tc_encodings,
! ARRAY_LENGTH(tc_charsets),
tc_charsets,
"cns_roman",
"BIG5"
},
{
! ARRAY_LENGTH(k_encodings),
k_encodings,
! ARRAY_LENGTH(k_charsets),
k_charsets,
"ks_roman",
"KS_X_1992"
***************
*** 1793,1804 ****
return FALSE;
// Find type of DSC comment
! for (comment = 0; comment < (int)NUM_ELEMENTS(prt_dsc_table); comment++)
if (prt_resfile_strncmp(0, prt_dsc_table[comment].string,
prt_dsc_table[comment].len) == 0)
break;
! if (comment != NUM_ELEMENTS(prt_dsc_table))
{
// Return type of comment
p_dsc_line->type = prt_dsc_table[comment].type;
--- 1791,1802 ----
return FALSE;
// Find type of DSC comment
! for (comment = 0; comment < (int)ARRAY_LENGTH(prt_dsc_table); comment++)
if (prt_resfile_strncmp(0, prt_dsc_table[comment].string,
prt_dsc_table[comment].len) == 0)
break;
! if (comment != ARRAY_LENGTH(prt_dsc_table))
{
// Return type of comment
p_dsc_line->type = prt_dsc_table[comment].type;
***************
*** 2385,2391 ****
int cmap_first = 0;
p_mbenc_first = NULL;
! for (cmap = 0; cmap < (int)NUM_ELEMENTS(prt_ps_mbfonts); cmap++)
if (prt_match_encoding((char *)p_encoding, &prt_ps_mbfonts[cmap],
&p_mbenc))
{
--- 2383,2389 ----
int cmap_first = 0;
p_mbenc_first = NULL;
! for (cmap = 0; cmap < (int)ARRAY_LENGTH(prt_ps_mbfonts); cmap++)
if (prt_match_encoding((char *)p_encoding, &prt_ps_mbfonts[cmap],
&p_mbenc))
{
*** ../vim-8.2.2921/src/help.c 2020-12-18 19:49:52.341571870 +0100
--- src/help.c 2021-06-02 13:22:19.123869308 +0200
***************
*** 381,387 ****
// When the string starting with "expr-" and containing '?' and matches
// the table, it is taken literally (but ~ is escaped). Otherwise '?'
// is recognized as a wildcard.
! for (i = (int)(sizeof(expr_table) / sizeof(char *)); --i >= 0; )
if (STRCMP(arg + 5, expr_table[i]) == 0)
{
int si = 0, di = 0;
--- 381,387 ----
// When the string starting with "expr-" and containing '?' and matches
// the table, it is taken literally (but ~ is escaped). Otherwise '?'
// is recognized as a wildcard.
! for (i = (int)ARRAY_LENGTH(expr_table); --i >= 0; )
if (STRCMP(arg + 5, expr_table[i]) == 0)
{
int si = 0, di = 0;
*** ../vim-8.2.2921/src/highlight.c 2020-09-29 20:59:13.561602886 +0200
--- src/highlight.c 2021-06-02 13:22:19.123869308 +0200
***************
*** 998,1004 ****
off = 0;
while (arg[off] != NUL)
{
! for (i = sizeof(hl_attr_table) / sizeof(int); --i >= 0; )
{
len = (int)STRLEN(hl_name_table[i]);
if (STRNICMP(arg + off, hl_name_table[i], len) == 0)
--- 998,1004 ----
off = 0;
while (arg[off] != NUL)
{
! for (i = ARRAY_LENGTH(hl_attr_table); --i >= 0; )
{
len = (int)STRLEN(hl_name_table[i]);
if (STRNICMP(arg + off, hl_name_table[i], len) == 0)
***************
*** 1168,1174 ****
// reduce calls to STRICMP a bit, it can be slow
off = TOUPPER_ASC(*arg);
! for (i = (sizeof(color_names) / sizeof(char *)); --i >= 0; )
if (off == color_names[i][0]
&& STRICMP(arg + 1, color_names[i] + 1) == 0)
break;
--- 1168,1174 ----
// reduce calls to STRICMP a bit, it can be slow
off = TOUPPER_ASC(*arg);
! for (i = ARRAY_LENGTH(color_names); --i >= 0; )
if (off == color_names[i][0]
&& STRICMP(arg + 1, color_names[i] + 1) == 0)
break;
*** ../vim-8.2.2921/src/if_mzsch.c 2020-12-31 17:40:57.536087870 +0100
--- src/if_mzsch.c 2021-06-02 13:22:19.123869308 +0200
***************
*** 3799,3805 ****
mod = scheme_primitive_module(vimext_symbol, environment);
MZ_GC_CHECK();
// all prims made closed so they can access their own names
! for (i = 0; i < (int)(sizeof(prims)/sizeof(prims[0])); i++)
{
Vim_Prim *prim = prims + i;
closed_prim = scheme_make_closed_prim_w_arity(prim->prim, prim, prim->name,
--- 3799,3805 ----
mod = scheme_primitive_module(vimext_symbol, environment);
MZ_GC_CHECK();
// all prims made closed so they can access their own names
! for (i = 0; i < (int)ARRAY_LENGTH(prims); i++)
{
Vim_Prim *prim = prims + i;
closed_prim = scheme_make_closed_prim_w_arity(prim->prim, prim, prim->name,
*** ../vim-8.2.2921/src/macros.h 2021-03-04 21:55:54.601235264 +0100
--- src/macros.h 2021-06-02 13:22:19.123869308 +0200
***************
*** 396,398 ****
--- 396,401 ----
#ifndef MAX
# define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
+
+ // Length of the array.
+ #define ARRAY_LENGTH(a) (sizeof(a) / sizeof((a)[0]))
*** ../vim-8.2.2921/src/main.c 2021-05-29 19:53:46.455055663 +0200
--- src/main.c 2021-06-02 13:26:28.267342617 +0200
***************
*** 645,651 ****
#endif
/*
! * When done something that is not allowed or error message call
* wait_return. This must be done before starttermcap(), because it may
* switch to another screen. It must be done after settmode(TMODE_RAW),
* because we want to react on a single key stroke.
--- 645,651 ----
#endif
/*
! * When done something that is not allowed or given an error message call
* wait_return. This must be done before starttermcap(), because it may
* switch to another screen. It must be done after settmode(TMODE_RAW),
* because we want to react on a single key stroke.
***************
*** 1662,1668 ****
{
// give the user a chance to read the (error) message
no_wait_return = FALSE;
! wait_return(FALSE);
}
// Position the cursor again, the autocommands may have moved it
--- 1662,1668 ----
{
// give the user a chance to read the (error) message
no_wait_return = FALSE;
! // wait_return(FALSE);
}
// Position the cursor again, the autocommands may have moved it
***************
*** 3435,3441 ****
{
mch_msg(_(" vim [arguments] "));
mch_msg(_(use[i]));
! if (i == (sizeof(use) / sizeof(char_u *)) - 1)
break;
mch_msg(_("\n or:"));
}
--- 3435,3441 ----
{
mch_msg(_(" vim [arguments] "));
mch_msg(_(use[i]));
! if (i == ARRAY_LENGTH(use) - 1)
break;
mch_msg(_("\n or:"));
}
*** ../vim-8.2.2921/src/map.c 2021-05-03 18:57:02.392070898 +0200
--- src/map.c 2021-06-02 13:22:19.123869308 +0200
***************
*** 2478,2490 ****
if (!gui.starting)
# endif
{
! for (i = 0;
! i < (int)(sizeof(cinitmappings) / sizeof(struct initmap)); ++i)
add_map(cinitmappings[i].arg, cinitmappings[i].mode);
}
# endif
# if defined(FEAT_GUI_MSWIN) || defined(MACOS_X)
! for (i = 0; i < (int)(sizeof(initmappings) / sizeof(struct initmap)); ++i)
add_map(initmappings[i].arg, initmappings[i].mode);
# endif
#endif
--- 2478,2489 ----
if (!gui.starting)
# endif
{
! for (i = 0; i < (int)ARRAY_LENGTH(cinitmappings); ++i)
add_map(cinitmappings[i].arg, cinitmappings[i].mode);
}
# endif
# if defined(FEAT_GUI_MSWIN) || defined(MACOS_X)
! for (i = 0; i < (int)ARRAY_LENGTH(initmappings); ++i)
add_map(initmappings[i].arg, initmappings[i].mode);
# endif
#endif
*** ../vim-8.2.2921/src/mbyte.c 2021-05-31 18:40:45.996805282 +0200
--- src/mbyte.c 2021-06-02 13:22:19.123869308 +0200
***************
*** 2850,2856 ****
};
int bot = 0;
! int top = sizeof(classes) / sizeof(struct clinterval) - 1;
int mid;
// First quick check for Latin1 characters, use 'iskeyword'.
--- 2850,2856 ----
};
int bot = 0;
! int top = ARRAY_LENGTH(classes) - 1;
int mid;
// First quick check for Latin1 characters, use 'iskeyword'.
***************
*** 3948,3954 ****
};
int first = 0;
! int last = sizeof(BOL_prohibition_punct)/sizeof(int) - 1;
int mid = 0;
while (first < last)
--- 3948,3954 ----
};
int first = 0;
! int last = ARRAY_LENGTH(BOL_prohibition_punct) - 1;
int mid = 0;
while (first < last)
***************
*** 3998,4004 ****
};
int first = 0;
! int last = sizeof(EOL_prohibition_punct)/sizeof(int) - 1;
int mid = 0;
while (first < last)
--- 3998,4004 ----
};
int first = 0;
! int last = ARRAY_LENGTH(EOL_prohibition_punct) - 1;
int mid = 0;
while (first < last)
*** ../vim-8.2.2921/src/memline.c 2021-05-26 22:32:06.254066656 +0200
--- src/memline.c 2021-06-02 13:22:19.123869308 +0200
***************
*** 1312,1318 ****
}
#ifdef FEAT_CRYPT
! for (i = 0; i < (int)(sizeof(id1_codes) / sizeof(int)); ++i)
if (id1_codes[i] == b0p->b0_id[1])
b0_cm = i;
if (b0_cm > 0)
--- 1312,1318 ----
}
#ifdef FEAT_CRYPT
! for (i = 0; i < (int)ARRAY_LENGTH(id1_codes); ++i)
if (id1_codes[i] == b0p->b0_id[1])
b0_cm = i;
if (b0_cm > 0)
*** ../vim-8.2.2921/src/menu.c 2020-12-28 18:25:56.800886000 +0100
--- src/menu.c 2021-06-02 13:22:19.123869308 +0200
***************
*** 73,79 ****
/* 25 */ "Make", "TagJump", "RunCtags", "WinVSplit", "WinMaxWidth",
/* 30 */ "WinMinWidth", "Exit"
};
! # define TOOLBAR_NAME_COUNT (sizeof(toolbar_names) / sizeof(char *))
#endif
/*
--- 73,79 ----
/* 25 */ "Make", "TagJump", "RunCtags", "WinVSplit", "WinMaxWidth",
/* 30 */ "WinMinWidth", "Exit"
};
! # define TOOLBAR_NAME_COUNT ARRAY_LENGTH(toolbar_names)
#endif
/*
*** ../vim-8.2.2921/src/misc2.c 2021-04-06 20:21:55.299147728 +0200
--- src/misc2.c 2021-06-02 13:27:04.975263803 +0200
***************
*** 1050,1056 ****
if (entered_free_all_mem)
return;
entered_free_all_mem = TRUE;
-
// Don't want to trigger autocommands from here on.
block_autocmds();
--- 1050,1055 ----
***************
*** 2542,2548 ****
// NOTE: When adding a long name update MAX_KEY_NAME_LEN.
};
! #define KEY_NAMES_TABLE_LEN (sizeof(key_names_table) / sizeof(struct key_name_entry))
/*
* Return the modifier mask bit (MOD_MASK_*) which corresponds to the given
--- 2541,2547 ----
// NOTE: When adding a long name update MAX_KEY_NAME_LEN.
};
! #define KEY_NAMES_TABLE_LEN ARRAY_LENGTH(key_names_table)
/*
* Return the modifier mask bit (MOD_MASK_*) which corresponds to the given
*** ../vim-8.2.2921/src/normal.c 2021-05-30 22:17:21.035457554 +0200
--- src/normal.c 2021-06-02 13:22:19.123869308 +0200
***************
*** 379,385 ****
};
// Number of commands in nv_cmds[].
! #define NV_CMDS_SIZE (sizeof(nv_cmds) / sizeof(struct nv_cmd))
// Sorted index of commands in nv_cmds[].
static short nv_cmd_idx[NV_CMDS_SIZE];
--- 379,385 ----
};
// Number of commands in nv_cmds[].
! #define NV_CMDS_SIZE ARRAY_LENGTH(nv_cmds)
// Sorted index of commands in nv_cmds[].
static short nv_cmd_idx[NV_CMDS_SIZE];
*** ../vim-8.2.2921/src/ops.c 2021-05-31 19:22:58.583454940 +0200
--- src/ops.c 2021-06-02 13:22:19.123869308 +0200
***************
*** 82,88 ****
{
if (opchars[i][0] == char1 && opchars[i][1] == char2)
break;
! if (i == (int)(sizeof(opchars) / sizeof(char [3]) - 1))
{
internal_error("get_op_type()");
break;
--- 82,88 ----
{
if (opchars[i][0] == char1 && opchars[i][1] == char2)
break;
! if (i == (int)ARRAY_LENGTH(opchars) - 1)
{
internal_error("get_op_type()");
break;
*** ../vim-8.2.2921/src/option.c 2021-05-30 18:04:14.714468918 +0200
--- src/option.c 2021-06-02 13:22:19.123869308 +0200
***************
*** 145,151 ****
opt_idx = findoption((char_u *)"backupskip");
ga_init2(&ga, 1, 100);
! for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
{
mustfree = FALSE;
# ifdef UNIX
--- 145,151 ----
opt_idx = findoption((char_u *)"backupskip");
ga_init2(&ga, 1, 100);
! for (n = 0; n < (long)ARRAY_LENGTH(names); ++n)
{
mustfree = FALSE;
# ifdef UNIX
***************
*** 6317,6324 ****
regmatch->rm_ic = ic;
if (xp->xp_context != EXPAND_BOOL_SETTINGS)
{
! for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
! ++match)
if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
{
if (loop == 0)
--- 6317,6323 ----
regmatch->rm_ic = ic;
if (xp->xp_context != EXPAND_BOOL_SETTINGS)
{
! for (match = 0; match < (int)ARRAY_LENGTH(names); ++match)
if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
{
if (loop == 0)
*** ../vim-8.2.2921/src/optiondefs.h 2021-03-29 20:49:01.486055361 +0200
--- src/optiondefs.h 2021-06-02 13:22:19.127869299 +0200
***************
*** 3033,3039 ****
{NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCTX_INIT}
};
! #define OPTION_COUNT (sizeof(options) / sizeof(struct vimoption))
// The following is needed to make the gen_opt_test.vim script work.
// {"
--- 3033,3039 ----
{NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCTX_INIT}
};
! #define OPTION_COUNT ARRAY_LENGTH(options)
// The following is needed to make the gen_opt_test.vim script work.
// {"
*** ../vim-8.2.2921/src/os_win32.c 2021-05-30 19:29:37.786489673 +0200
--- src/os_win32.c 2021-06-02 13:22:19.127869299 +0200
***************
*** 1105,1111 ****
return TRUE;
}
! for (i = sizeof(VirtKeyMap) / sizeof(VirtKeyMap[0]); --i >= 0; )
{
if (VirtKeyMap[i].wVirtKey == pker->wVirtualKeyCode)
{
--- 1105,1111 ----
return TRUE;
}
! for (i = ARRAY_LENGTH(VirtKeyMap); --i >= 0; )
{
if (VirtKeyMap[i].wVirtKey == pker->wVirtualKeyCode)
{
***************
*** 3045,3051 ****
int len)
{
WCHAR wszUserName[256 + 1]; // UNLEN is 256
! DWORD wcch = sizeof(wszUserName) / sizeof(WCHAR);
if (GetUserNameW(wszUserName, &wcch))
{
--- 3045,3051 ----
int len)
{
WCHAR wszUserName[256 + 1]; // UNLEN is 256
! DWORD wcch = ARRAY_LENGTH(wszUserName);
if (GetUserNameW(wszUserName, &wcch))
{
***************
*** 3072,3078 ****
int len)
{
WCHAR wszHostName[256 + 1];
! DWORD wcch = sizeof(wszHostName) / sizeof(WCHAR);
if (GetComputerNameW(wszHostName, &wcch))
{
--- 3072,3078 ----
int len)
{
WCHAR wszHostName[256 + 1];
! DWORD wcch = ARRAY_LENGTH(wszHostName);
if (GetComputerNameW(wszHostName, &wcch))
{
***************
*** 4757,4764 ****
WCHAR szShellTitle[512];
// Change the title to reflect that we are in a subshell.
! if (GetConsoleTitleW(szShellTitle,
! sizeof(szShellTitle)/sizeof(WCHAR) - 4) > 0)
{
if (cmd == NULL)
wcscat(szShellTitle, L" :sh");
--- 4757,4763 ----
WCHAR szShellTitle[512];
// Change the title to reflect that we are in a subshell.
! if (GetConsoleTitleW(szShellTitle, ARRAY_LENGTH(szShellTitle) - 4) > 0)
{
if (cmd == NULL)
wcscat(szShellTitle, L" :sh");
***************
*** 4770,4776 ****
{
wcscat(szShellTitle, L" - !");
if ((wcslen(szShellTitle) + wcslen(wn) <
! sizeof(szShellTitle)/sizeof(WCHAR)))
wcscat(szShellTitle, wn);
SetConsoleTitleW(szShellTitle);
vim_free(wn);
--- 4769,4775 ----
{
wcscat(szShellTitle, L" - !");
if ((wcslen(szShellTitle) + wcslen(wn) <
! ARRAY_LENGTH(szShellTitle)))
wcscat(szShellTitle, wn);
SetConsoleTitleW(szShellTitle);
vim_free(wn);
*** ../vim-8.2.2921/src/popupwin.c 2021-05-28 14:11:59.725797039 +0200
--- src/popupwin.c 2021-06-02 13:22:19.127869299 +0200
***************
*** 402,409 ****
if (str == NULL)
return POPPOS_NONE;
! for (nr = 0; nr < (int)(sizeof(poppos_entries) / sizeof(poppos_entry_T));
! ++nr)
if (STRCMP(str, poppos_entries[nr].pp_name) == 0)
return poppos_entries[nr].pp_val;
--- 402,408 ----
if (str == NULL)
return POPPOS_NONE;
! for (nr = 0; nr < (int)ARRAY_LENGTH(poppos_entries); ++nr)
if (STRCMP(str, poppos_entries[nr].pp_name) == 0)
return poppos_entries[nr].pp_val;
***************
*** 3042,3049 ****
if (wp->w_close_cb.cb_name != NULL)
dict_add_callback(dict, "callback", &wp->w_close_cb);
! for (i = 0; i < (int)(sizeof(poppos_entries) / sizeof(poppos_entry_T));
! ++i)
if (wp->w_popup_pos == poppos_entries[i].pp_val)
{
dict_add_string(dict, "pos",
--- 3041,3047 ----
if (wp->w_close_cb.cb_name != NULL)
dict_add_callback(dict, "callback", &wp->w_close_cb);
! for (i = 0; i < (int)ARRAY_LENGTH(poppos_entries); ++i)
if (wp->w_popup_pos == poppos_entries[i].pp_val)
{
dict_add_string(dict, "pos",
*** ../vim-8.2.2921/src/quickfix.c 2021-05-05 21:31:36.068018579 +0200
--- src/quickfix.c 2021-06-02 13:22:19.127869299 +0200
***************
*** 5971,5977 ****
char_u *str = ml_get_buf(buf, lnum, FALSE);
int score;
int_u matches[MAX_FUZZY_MATCHES];
! int_u sz = sizeof(matches) / sizeof(matches[0]);
// Fuzzy string match
while (fuzzy_match(str + col, spat, FALSE, &score, matches, sz) > 0)
--- 5971,5977 ----
char_u *str = ml_get_buf(buf, lnum, FALSE);
int score;
int_u matches[MAX_FUZZY_MATCHES];
! int_u sz = ARRAY_LENGTH(matches);
// Fuzzy string match
while (fuzzy_match(str + col, spat, FALSE, &score, matches, sz) > 0)
*** ../vim-8.2.2921/src/regexp.c 2021-05-30 16:42:53.642691771 +0200
--- src/regexp.c 2021-06-02 13:22:19.127869299 +0200
***************
*** 202,208 ****
if ((*pp)[1] == ':')
{
! for (i = 0; i < (int)(sizeof(class_names) / sizeof(*class_names)); ++i)
if (STRNCMP(*pp + 2, class_names[i], STRLEN(class_names[i])) == 0)
{
*pp += STRLEN(class_names[i]) + 2;
--- 202,208 ----
if ((*pp)[1] == ':')
{
! for (i = 0; i < (int)ARRAY_LENGTH(class_names); ++i)
if (STRNCMP(*pp + 2, class_names[i], STRLEN(class_names[i])) == 0)
{
*pp += STRLEN(class_names[i]) + 2;
*** ../vim-8.2.2921/src/screen.c 2021-04-01 16:15:59.184829183 +0200
--- src/screen.c 2021-06-02 13:22:19.127869299 +0200
***************
*** 4817,4830 ****
{
tab = lcstab;
CLEAR_FIELD(lcs_chars);
! entries = sizeof(lcstab) / sizeof(struct charstab);
if (varp == &wp->w_p_lcs && wp->w_p_lcs[0] == NUL)
varp = &p_lcs;
}
else
{
tab = filltab;
! entries = sizeof(filltab) / sizeof(struct charstab);
}
// first round: check for valid value, second round: assign values
--- 4817,4830 ----
{
tab = lcstab;
CLEAR_FIELD(lcs_chars);
! entries = ARRAY_LENGTH(lcstab);
if (varp == &wp->w_p_lcs && wp->w_p_lcs[0] == NUL)
varp = &p_lcs;
}
else
{
tab = filltab;
! entries = ARRAY_LENGTH(filltab);
}
// first round: check for valid value, second round: assign values
*** ../vim-8.2.2921/src/search.c 2021-04-26 21:14:12.713924760 +0200
--- src/search.c 2021-06-02 13:22:19.127869299 +0200
***************
*** 4444,4450 ****
if (fuzzy_match_recursive(fuzpat, next_char, strIdx + 1,
&recursiveScore, strBegin, strLen, matches,
recursiveMatches,
! sizeof(recursiveMatches)/sizeof(recursiveMatches[0]),
nextMatch, recursionCount))
{
// Pick best recursive score
--- 4444,4450 ----
if (fuzzy_match_recursive(fuzpat, next_char, strIdx + 1,
&recursiveScore, strBegin, strLen, matches,
recursiveMatches,
! ARRAY_LENGTH(recursiveMatches),
nextMatch, recursionCount))
{
// Pick best recursive score
*** ../vim-8.2.2921/src/syntax.c 2021-04-14 11:15:05.336785013 +0200
--- src/syntax.c 2021-06-02 13:22:19.127869299 +0200
***************
*** 4573,4579 ****
if (strchr(first_letters, *arg) == NULL)
break;
! for (fidx = sizeof(flagtab) / sizeof(struct flag); --fidx >= 0; )
{
p = flagtab[fidx].name;
for (i = 0, len = 0; p[i] != NUL; i += 2, ++len)
--- 4573,4579 ----
if (strchr(first_letters, *arg) == NULL)
break;
! for (fidx = ARRAY_LENGTH(flagtab); --fidx >= 0; )
{
p = flagtab[fidx].name;
for (i = 0, len = 0; p[i] != NUL; i += 2, ++len)
*** ../vim-8.2.2921/src/term.c 2021-05-29 22:34:15.410318351 +0200
--- src/term.c 2021-06-02 13:22:19.127869299 +0200
***************
*** 6725,6731 ****
}
// Check if the name is one of the colors we know
! for (i = 0; i < (int)(sizeof(rgb_table) / sizeof(rgb_table[0])); i++)
if (STRICMP(name, rgb_table[i].color_name) == 0)
return gui_adjust_rgb(rgb_table[i].color);
--- 6725,6731 ----
}
// Check if the name is one of the colors we know
! for (i = 0; i < (int)ARRAY_LENGTH(rgb_table); i++)
if (STRICMP(name, rgb_table[i].color_name) == 0)
return gui_adjust_rgb(rgb_table[i].color);
*** ../vim-8.2.2921/src/terminal.c 2021-05-30 13:53:43.220969186 +0200
--- src/terminal.c 2021-06-02 13:22:19.127869299 +0200
***************
*** 5691,5697 ****
if (attr > HL_ALL)
attr = syn_attr2attr(attr);
! for (i = 0; i < sizeof(attrs)/sizeof(attrs[0]); ++i)
if (STRCMP(name, attrs[i].name) == 0)
{
rettv->vval.v_number = (attr & attrs[i].attr) != 0 ? 1 : 0;
--- 5691,5697 ----
if (attr > HL_ALL)
attr = syn_attr2attr(attr);
! for (i = 0; i < ARRAY_LENGTH(attrs); ++i)
if (STRCMP(name, attrs[i].name) == 0)
{
rettv->vval.v_number = (attr & attrs[i].attr) != 0 ? 1 : 0;
*** ../vim-8.2.2921/src/time.c 2021-05-28 15:49:29.254504153 +0200
--- src/time.c 2021-06-02 13:22:19.127869299 +0200
***************
*** 276,283 ****
wp = enc_to_utf16(p, NULL);
if (wp != NULL)
! (void)wcsftime(result_buf, sizeof(result_buf) / sizeof(WCHAR),
! wp, curtime);
else
result_buf[0] = NUL;
rettv->vval.v_string = utf16_to_enc(result_buf, NULL);
--- 276,282 ----
wp = enc_to_utf16(p, NULL);
if (wp != NULL)
! (void)wcsftime(result_buf, ARRAY_LENGTH(result_buf), wp, curtime);
else
result_buf[0] = NUL;
rettv->vval.v_string = utf16_to_enc(result_buf, NULL);
*** ../vim-8.2.2921/src/usercmd.c 2020-12-28 18:25:56.800886000 +0100
--- src/usercmd.c 2021-06-02 13:22:19.131869290 +0200
***************
*** 339,345 ****
"count", "nargs", "range", "register"
};
! if (idx >= (int)(sizeof(user_cmd_flags) / sizeof(user_cmd_flags[0])))
return NULL;
return (char_u *)user_cmd_flags[idx];
}
--- 339,345 ----
"count", "nargs", "range", "register"
};
! if (idx >= (int)ARRAY_LENGTH(user_cmd_flags))
return NULL;
return (char_u *)user_cmd_flags[idx];
}
***************
*** 352,358 ****
{
static char *user_cmd_nargs[] = {"0", "1", "*", "?", "+"};
! if (idx >= (int)(sizeof(user_cmd_nargs) / sizeof(user_cmd_nargs[0])))
return NULL;
return (char_u *)user_cmd_nargs[idx];
}
--- 352,358 ----
{
static char *user_cmd_nargs[] = {"0", "1", "*", "?", "+"};
! if (idx >= (int)ARRAY_LENGTH(user_cmd_nargs))
return NULL;
return (char_u *)user_cmd_nargs[idx];
}
*** ../vim-8.2.2921/src/version.c 2021-06-02 11:49:19.268325065 +0200
--- src/version.c 2021-06-02 13:24:41.383570517 +0200
***************
*** 6627,6633 ****
// Perform a binary search.
l = 0;
! h = (int)(sizeof(included_patches) / sizeof(included_patches[0])) - 1;
while (l < h)
{
m = (l + h) / 2;
--- 6629,6635 ----
// Perform a binary search.
l = 0;
! h = (int)ARRAY_LENGTH(included_patches) - 1;
while (l < h)
{
m = (l + h) / 2;
***************
*** 6854,6860 ****
{
msg_puts(_("\nIncluded patches: "));
first = -1;
! i = (int)(sizeof(included_patches) / sizeof(included_patches[0])) - 1;
while (--i >= 0)
{
if (first < 0)
--- 6856,6862 ----
{
msg_puts(_("\nIncluded patches: "));
first = -1;
! i = (int)ARRAY_LENGTH(included_patches) - 1;
while (--i >= 0)
{
if (first < 0)
***************
*** 7145,7151 ****
#endif
// blanklines = screen height - # message lines
! blanklines = (int)Rows - ((sizeof(lines) / sizeof(char *)) - 1);
if (!p_cp)
blanklines += 4; // add 4 for not showing "Vi compatible" message
--- 7147,7153 ----
#endif
// blanklines = screen height - # message lines
! blanklines = (int)Rows - (ARRAY_LENGTH(lines) - 1);
if (!p_cp)
blanklines += 4; // add 4 for not showing "Vi compatible" message
***************
*** 7164,7170 ****
row = blanklines / 2;
if ((row >= 2 && Columns >= 50) || colon)
{
! for (i = 0; i < (int)(sizeof(lines) / sizeof(char *)); ++i)
{
p = lines[i];
#ifdef FEAT_GUI
--- 7166,7172 ----
row = blanklines / 2;
if ((row >= 2 && Columns >= 50) || colon)
{
! for (i = 0; i < (int)ARRAY_LENGTH(lines); ++i)
{
p = lines[i];
#ifdef FEAT_GUI
*** ../vim-8.2.2921/src/version.c 2021-06-02 11:49:19.268325065 +0200
--- src/version.c 2021-06-02 13:24:41.383570517 +0200
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 2922,
/**/
--
SIGFUN -- signature too funny (core dumped)
/// Bram Moolenaar -- Br...@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 ///