vim-patch:8.0.1688: some macros are used without a semicolon

Problem:    Some macros are used without a semicolon, causing auto-indent to be
            wrong.
Solution:   Use the do-while(0) trick. (Ozaki Kiichi, closes vim/vim#2729)
6f4700233f
This commit is contained in:
Jan Edmund Lazo
2019-06-25 22:38:13 -04:00
parent 62c7fcbdab
commit 2d6c91ab99
4 changed files with 81 additions and 58 deletions

View File

@@ -1,9 +1,9 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check // This is an open source non-commercial project. Dear PVS-Studio, please check
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
/* for debugging */ // for debugging
/* #define CHECK(c, s) if (c) EMSG(s) */ // #define CHECK(c, s) do { if (c) EMSG(s); } while (0)
#define CHECK(c, s) #define CHECK(c, s) do { } while (0)
/* /*
* memline.c: Contains the functions for appending, deleting and changing the * memline.c: Contains the functions for appending, deleting and changing the

View File

@@ -1709,7 +1709,6 @@ static void fold_line(win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T
int col; int col;
int txtcol; int txtcol;
int off; int off;
int ri;
/* Build the fold line: /* Build the fold line:
* 1. Add the cmdwin_type for the command-line window * 1. Add the cmdwin_type for the command-line window
@@ -1753,15 +1752,18 @@ static void fold_line(win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T
col += fdc; col += fdc;
} }
# define RL_MEMSET(p, v, l) if (wp->w_p_rl) { \ # define RL_MEMSET(p, v, l) \
for (ri = 0; ri < l; ri++) { \ do { \
linebuf_attr[off + (wp->w_grid.Columns - (p) - (l)) + ri] = v; \ if (wp->w_p_rl) { \
for (int ri = 0; ri < l; ri++) { \
linebuf_attr[off + (wp->w_grid.Columns - (p) - (l)) + ri] = v; \
} \
} else { \
for (int ri = 0; ri < l; ri++) { \
linebuf_attr[off + (p) + ri] = v; \
} \
} \ } \
} else { \ } while (0)
for (ri = 0; ri < l; ri++) { \
linebuf_attr[off + (p) + ri] = v; \
} \
}
/* Set all attributes of the 'number' or 'relativenumber' column and the /* Set all attributes of the 'number' or 'relativenumber' column and the
* text */ * text */

View File

@@ -4344,8 +4344,8 @@ find_pattern_in_path(
char_u *ptr, // pointer to search pattern char_u *ptr, // pointer to search pattern
int dir, // direction of expansion int dir, // direction of expansion
size_t len, // length of search pattern size_t len, // length of search pattern
int whole, // match whole words only bool whole, // match whole words only
int skip_comments, // don't match inside comments bool skip_comments, // don't match inside comments
int type, // Type of search; are we looking for a type? int type, // Type of search; are we looking for a type?
// a macro? // a macro?
long count, long count,

View File

@@ -90,36 +90,47 @@ do_window (
else else
Prenum1 = Prenum; Prenum1 = Prenum;
# define CHECK_CMDWIN if (cmdwin_type != 0) { EMSG(_(e_cmdwin)); break; } # define CHECK_CMDWIN \
do { \
if (cmdwin_type != 0) { \
EMSG(_(e_cmdwin)); \
return; \
} \
} while (0)
switch (nchar) { switch (nchar) {
/* split current window in two parts, horizontally */ /* split current window in two parts, horizontally */
case 'S': case 'S':
case Ctrl_S: case Ctrl_S:
case 's': case 's':
CHECK_CMDWIN reset_VIsual_and_resel(); /* stop Visual mode */ CHECK_CMDWIN;
/* When splitting the quickfix window open a new buffer in it, reset_VIsual_and_resel(); // stop Visual mode
* don't replicate the quickfix buffer. */ // When splitting the quickfix window open a new buffer in it,
if (bt_quickfix(curbuf)) // don't replicate the quickfix buffer.
if (bt_quickfix(curbuf)) {
goto newwindow; goto newwindow;
}
(void)win_split((int)Prenum, 0); (void)win_split((int)Prenum, 0);
break; break;
/* split current window in two parts, vertically */ /* split current window in two parts, vertically */
case Ctrl_V: case Ctrl_V:
case 'v': case 'v':
CHECK_CMDWIN reset_VIsual_and_resel(); /* stop Visual mode */ CHECK_CMDWIN;
/* When splitting the quickfix window open a new buffer in it, reset_VIsual_and_resel(); // stop Visual mode
* don't replicate the quickfix buffer. */ // When splitting the quickfix window open a new buffer in it,
if (bt_quickfix(curbuf)) // don't replicate the quickfix buffer.
if (bt_quickfix(curbuf)) {
goto newwindow; goto newwindow;
}
(void)win_split((int)Prenum, WSP_VERT); (void)win_split((int)Prenum, WSP_VERT);
break; break;
/* split current window and edit alternate file */ /* split current window and edit alternate file */
case Ctrl_HAT: case Ctrl_HAT:
case '^': case '^':
CHECK_CMDWIN reset_VIsual_and_resel(); /* stop Visual mode */ CHECK_CMDWIN;
reset_VIsual_and_resel(); // stop Visual mode
cmd_with_count("split #", (char_u *)cbuf, sizeof(cbuf), Prenum); cmd_with_count("split #", (char_u *)cbuf, sizeof(cbuf), Prenum);
do_cmdline_cmd(cbuf); do_cmdline_cmd(cbuf);
break; break;
@@ -127,7 +138,8 @@ do_window (
/* open new window */ /* open new window */
case Ctrl_N: case Ctrl_N:
case 'n': case 'n':
CHECK_CMDWIN reset_VIsual_and_resel(); /* stop Visual mode */ CHECK_CMDWIN;
reset_VIsual_and_resel(); // stop Visual mode
newwindow: newwindow:
if (Prenum) if (Prenum)
/* window height */ /* window height */
@@ -160,7 +172,8 @@ newwindow:
/* close preview window */ /* close preview window */
case Ctrl_Z: case Ctrl_Z:
case 'z': case 'z':
CHECK_CMDWIN reset_VIsual_and_resel(); /* stop Visual mode */ CHECK_CMDWIN;
reset_VIsual_and_resel(); // stop Visual mode
do_cmdline_cmd("pclose"); do_cmdline_cmd("pclose");
break; break;
@@ -183,7 +196,8 @@ newwindow:
/* close all but current window */ /* close all but current window */
case Ctrl_O: case Ctrl_O:
case 'o': case 'o':
CHECK_CMDWIN reset_VIsual_and_resel(); /* stop Visual mode */ CHECK_CMDWIN;
reset_VIsual_and_resel(); // stop Visual mode
cmd_with_count("only", (char_u *)cbuf, sizeof(cbuf), Prenum); cmd_with_count("only", (char_u *)cbuf, sizeof(cbuf), Prenum);
do_cmdline_cmd(cbuf); do_cmdline_cmd(cbuf);
break; break;
@@ -193,11 +207,11 @@ newwindow:
case 'w': case 'w':
/* cursor to previous window with wrap around */ /* cursor to previous window with wrap around */
case 'W': case 'W':
CHECK_CMDWIN CHECK_CMDWIN;
if (ONE_WINDOW && Prenum != 1) /* just one window */ if (ONE_WINDOW && Prenum != 1) { // just one window
beep_flush(); beep_flush();
else { } else {
if (Prenum) { /* go to specified window */ if (Prenum) { // go to specified window
for (wp = firstwin; --Prenum > 0; ) { for (wp = firstwin; --Prenum > 0; ) {
if (wp->w_next == NULL) if (wp->w_next == NULL)
break; break;
@@ -233,14 +247,16 @@ newwindow:
case 'j': case 'j':
case K_DOWN: case K_DOWN:
case Ctrl_J: case Ctrl_J:
CHECK_CMDWIN win_goto_ver(FALSE, Prenum1); CHECK_CMDWIN;
win_goto_ver(false, Prenum1);
break; break;
/* cursor to window above */ /* cursor to window above */
case 'k': case 'k':
case K_UP: case K_UP:
case Ctrl_K: case Ctrl_K:
CHECK_CMDWIN win_goto_ver(TRUE, Prenum1); CHECK_CMDWIN;
win_goto_ver(true, Prenum1);
break; break;
/* cursor to left window */ /* cursor to left window */
@@ -248,14 +264,16 @@ newwindow:
case K_LEFT: case K_LEFT:
case Ctrl_H: case Ctrl_H:
case K_BS: case K_BS:
CHECK_CMDWIN win_goto_hor(TRUE, Prenum1); CHECK_CMDWIN;
win_goto_hor(true, Prenum1);
break; break;
/* cursor to right window */ /* cursor to right window */
case 'l': case 'l':
case K_RIGHT: case K_RIGHT:
case Ctrl_L: case Ctrl_L:
CHECK_CMDWIN win_goto_hor(FALSE, Prenum1); CHECK_CMDWIN;
win_goto_hor(false, Prenum1);
break; break;
/* move window to new tab page */ /* move window to new tab page */
@@ -309,20 +327,23 @@ newwindow:
/* exchange current and next window */ /* exchange current and next window */
case 'x': case 'x':
case Ctrl_X: case Ctrl_X:
CHECK_CMDWIN win_exchange(Prenum); CHECK_CMDWIN;
win_exchange(Prenum);
break; break;
/* rotate windows downwards */ /* rotate windows downwards */
case Ctrl_R: case Ctrl_R:
case 'r': case 'r':
CHECK_CMDWIN reset_VIsual_and_resel(); /* stop Visual mode */ CHECK_CMDWIN;
win_rotate(FALSE, (int)Prenum1); /* downwards */ reset_VIsual_and_resel(); // stop Visual mode
win_rotate(false, (int)Prenum1); // downwards
break; break;
/* rotate windows upwards */ /* rotate windows upwards */
case 'R': case 'R':
CHECK_CMDWIN reset_VIsual_and_resel(); /* stop Visual mode */ CHECK_CMDWIN;
win_rotate(TRUE, (int)Prenum1); /* upwards */ reset_VIsual_and_resel(); // stop Visual mode
win_rotate(true, (int)Prenum1); // upwards
break; break;
/* move window to the very top/bottom/left/right */ /* move window to the very top/bottom/left/right */
@@ -330,9 +351,10 @@ newwindow:
case 'J': case 'J':
case 'H': case 'H':
case 'L': case 'L':
CHECK_CMDWIN win_totop((int)Prenum, CHECK_CMDWIN;
((nchar == 'H' || nchar == 'L') ? WSP_VERT : 0) win_totop((int)Prenum,
| ((nchar == 'H' || nchar == 'K') ? WSP_TOP : WSP_BOT)); ((nchar == 'H' || nchar == 'L') ? WSP_VERT : 0)
| ((nchar == 'H' || nchar == 'K') ? WSP_TOP : WSP_BOT));
break; break;
/* make all windows the same height */ /* make all windows the same height */
@@ -373,15 +395,16 @@ newwindow:
/* jump to tag and split window if tag exists (in preview window) */ /* jump to tag and split window if tag exists (in preview window) */
case '}': case '}':
CHECK_CMDWIN CHECK_CMDWIN;
if (Prenum) if (Prenum) {
g_do_tagpreview = Prenum; g_do_tagpreview = Prenum;
else } else {
g_do_tagpreview = p_pvh; g_do_tagpreview = p_pvh;
}
FALLTHROUGH; FALLTHROUGH;
case ']': case ']':
case Ctrl_RSB: case Ctrl_RSB:
CHECK_CMDWIN CHECK_CMDWIN;
// Keep visual mode, can select words to use as a tag. // Keep visual mode, can select words to use as a tag.
if (Prenum) if (Prenum)
postponed_split = Prenum; postponed_split = Prenum;
@@ -402,7 +425,7 @@ newwindow:
case 'F': case 'F':
case Ctrl_F: case Ctrl_F:
wingotofile: wingotofile:
CHECK_CMDWIN CHECK_CMDWIN;
ptr = grab_file_name(Prenum1, &lnum); ptr = grab_file_name(Prenum1, &lnum);
if (ptr != NULL) { if (ptr != NULL) {
@@ -434,11 +457,11 @@ wingotofile:
FALLTHROUGH; FALLTHROUGH;
case 'd': // Go to definition, using 'define' case 'd': // Go to definition, using 'define'
case Ctrl_D: case Ctrl_D:
CHECK_CMDWIN CHECK_CMDWIN;
if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0) if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0) {
break; break;
find_pattern_in_path(ptr, 0, len, TRUE, }
Prenum == 0 ? TRUE : FALSE, find_pattern_in_path(ptr, 0, len, true, Prenum == 0,
type, Prenum1, ACTION_SPLIT, 1, MAXLNUM); type, Prenum1, ACTION_SPLIT, 1, MAXLNUM);
curwin->w_set_curswant = TRUE; curwin->w_set_curswant = TRUE;
break; break;
@@ -455,7 +478,7 @@ wingotofile:
/* CTRL-W g extended commands */ /* CTRL-W g extended commands */
case 'g': case 'g':
case Ctrl_G: case Ctrl_G:
CHECK_CMDWIN CHECK_CMDWIN;
no_mapping++; no_mapping++;
if (xchar == NUL) { if (xchar == NUL) {
xchar = plain_vgetc(); xchar = plain_vgetc();
@@ -1631,11 +1654,9 @@ static void win_exchange(long Prenum)
redraw_win_later(wp, NOT_VALID); redraw_win_later(wp, NOT_VALID);
} }
/* // rotate windows: if upwards true the second window becomes the first one
* rotate windows: if upwards TRUE the second window becomes the first one // if upwards false the first window becomes the second one
* if upwards FALSE the first window becomes the second one static void win_rotate(bool upwards, int count)
*/
static void win_rotate(int upwards, int count)
{ {
win_T *wp1; win_T *wp1;
win_T *wp2; win_T *wp2;