Skip to content

Commit

Permalink
patch 8.2.4639: not sufficient parenthesis in preprocessor macros
Browse files Browse the repository at this point in the history
Problem:    Not sufficient parenthesis in preprocessor macros.
Solution:   Add more parenthesis. (closes #10031)
  • Loading branch information
kylo252 authored and brammool committed Mar 27, 2022
1 parent 3e559cd commit 9dac9b1
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 57 deletions.
10 changes: 5 additions & 5 deletions src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -702,10 +702,10 @@ EXTERN win_T *lastwin; // last window
EXTERN win_T *prevwin INIT(= NULL); // previous window
#define ONE_WINDOW (firstwin == lastwin)
#define W_NEXT(wp) ((wp)->w_next)
#define FOR_ALL_WINDOWS(wp) for (wp = firstwin; wp != NULL; wp = wp->w_next)
#define FOR_ALL_WINDOWS(wp) for ((wp) = firstwin; (wp) != NULL; (wp) = (wp)->w_next)
#define FOR_ALL_FRAMES(frp, first_frame) \
for (frp = first_frame; frp != NULL; frp = frp->fr_next)
#define FOR_ALL_TABPAGES(tp) for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
for ((frp) = first_frame; (frp) != NULL; (frp) = (frp)->fr_next)
#define FOR_ALL_TABPAGES(tp) for ((tp) = first_tabpage; (tp) != NULL; (tp) = (tp)->tp_next)
#define FOR_ALL_WINDOWS_IN_TAB(tp, wp) \
for ((wp) = ((tp) == NULL || (tp) == curtab) \
? firstwin : (tp)->tp_firstwin; (wp); (wp) = (wp)->w_next)
Expand Down Expand Up @@ -778,7 +778,7 @@ EXTERN buf_T *curbuf INIT(= NULL); // currently active buffer

// Iterate through all the signs placed in a buffer
#define FOR_ALL_SIGNS_IN_BUF(buf, sign) \
for (sign = buf->b_signlist; sign != NULL; sign = sign->se_next)
for ((sign) = (buf)->b_signlist; (sign) != NULL; (sign) = (sign)->se_next)

// Flag that is set when switching off 'swapfile'. It means that all blocks
// are to be loaded into memory. Shouldn't be global...
Expand Down Expand Up @@ -1000,7 +1000,7 @@ EXTERN JMP_BUF x_jump_env;
#define DBCS_CHT 950 // taiwan
#define DBCS_CHTU 9950 // euc-tw
#define DBCS_2BYTE 1 // 2byte-
#define DBCS_DEBUG -1
#define DBCS_DEBUG (-1)

EXTERN int enc_dbcs INIT(= 0); // One of DBCS_xxx values if
// DBCS encoding
Expand Down
6 changes: 3 additions & 3 deletions src/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
#endif

// Indices for arrays of scrollbars
#define SBAR_NONE -1
#define SBAR_NONE (-1)
#define SBAR_LEFT 0
#define SBAR_RIGHT 1
#define SBAR_BOTTOM 2
Expand Down Expand Up @@ -198,10 +198,10 @@ typedef struct GuiScrollbar
typedef long guicolor_T; // handle for a GUI color; for X11 this should
// be "Pixel", but that's an unsigned and we
// need a signed value
#define INVALCOLOR (guicolor_T)-11111 // number for invalid color; on 32 bit
#define INVALCOLOR ((guicolor_T)-11111) // number for invalid color; on 32 bit
// displays there is a tiny chance this is an
// actual color
#define CTERMCOLOR (guicolor_T)-11110 // only used for cterm.bg_rgb and
#define CTERMCOLOR ((guicolor_T)-11110) // only used for cterm.bg_rgb and
// cterm.fg_rgb: use cterm color

#ifdef FEAT_GUI_GTK
Expand Down
6 changes: 3 additions & 3 deletions src/if_py_both.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ static const char *vim_special_path = "_vim_path_";
#define PyErr_FORMAT2(exc, str, arg1, arg2) PyErr_Format(exc, _(str), arg1,arg2)
#define PyErr_VIM_FORMAT(str, arg) PyErr_FORMAT(VimError, str, arg)

#define Py_TYPE_NAME(obj) (obj->ob_type->tp_name == NULL \
#define Py_TYPE_NAME(obj) ((obj)->ob_type->tp_name == NULL \
? "(NULL)" \
: obj->ob_type->tp_name)
: (obj)->ob_type->tp_name)

#define RAISE_NO_EMPTY_KEYS PyErr_SET_STRING(PyExc_ValueError, \
N_("empty keys are not allowed"))
Expand Down Expand Up @@ -6686,7 +6686,7 @@ init_structs(void)
}

#define PYTYPE_READY(type) \
if (PyType_Ready(&type)) \
if (PyType_Ready(&(type))) \
return -1;

static int
Expand Down
10 changes: 5 additions & 5 deletions src/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@
// Advance multi-byte pointer, do not skip over composing chars.
#define MB_CPTR_ADV(p) p += enc_utf8 ? utf_ptr2len(p) : (*mb_ptr2len)(p)
// Backup multi-byte pointer. Only use with "p" > "s" !
#define MB_PTR_BACK(s, p) p -= has_mbyte ? ((*mb_head_off)(s, p - 1) + 1) : 1
#define MB_PTR_BACK(s, p) p -= has_mbyte ? ((*mb_head_off)(s, (p) - 1) + 1) : 1
// get length of multi-byte char, not including composing chars
#define MB_CPTR2LEN(p) (enc_utf8 ? utf_ptr2len(p) : (*mb_ptr2len)(p))

#define MB_COPY_CHAR(f, t) do { if (has_mbyte) mb_copy_char(&f, &t); else *t++ = *f++; } while (0)
#define MB_COPY_CHAR(f, t) do { if (has_mbyte) mb_copy_char(&(f), &(t)); else *(t)++ = *(f)++; } while (0)
#define MB_CHARLEN(p) (has_mbyte ? mb_charlen(p) : (int)STRLEN(p))
#define MB_CHAR2LEN(c) (has_mbyte ? mb_char2len(c) : 1)
#define PTR2CHAR(p) (has_mbyte ? mb_ptr2char(p) : (int)*(p))
Expand Down Expand Up @@ -313,7 +313,7 @@
* HI2DI() converts a hashitem pointer to a dictitem pointer.
*/
#define DI2HIKEY(di) ((di)->di_key)
#define HIKEY2DI(p) ((dictitem_T *)(p - offsetof(dictitem_T, di_key)))
#define HIKEY2DI(p) ((dictitem_T *)((p) - offsetof(dictitem_T, di_key)))
#define HI2DI(hi) HIKEY2DI((hi)->hi_key)

/*
Expand Down Expand Up @@ -376,9 +376,9 @@
#define CHECK_LIST_MATERIALIZE(l) if ((l)->lv_first == &range_list_item) range_list_materialize(l)

// Inlined version of ga_grow() with optimized condition that it fails.
#define GA_GROW_FAILS(gap, n) unlikely((((gap)->ga_maxlen - (gap)->ga_len < n) ? ga_grow_inner((gap), (n)) : OK) == FAIL)
#define GA_GROW_FAILS(gap, n) unlikely((((gap)->ga_maxlen - (gap)->ga_len < (n)) ? ga_grow_inner((gap), (n)) : OK) == FAIL)
// Inlined version of ga_grow() with optimized condition that it succeeds.
#define GA_GROW_OK(gap, n) likely((((gap)->ga_maxlen - (gap)->ga_len < n) ? ga_grow_inner((gap), (n)) : OK) == OK)
#define GA_GROW_OK(gap, n) likely((((gap)->ga_maxlen - (gap)->ga_len < (n)) ? ga_grow_inner((gap), (n)) : OK) == OK)

#ifndef MIN
# define MIN(a, b) ((a) < (b) ? (a) : (b))
Expand Down
4 changes: 2 additions & 2 deletions src/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ typedef enum {
#endif

// end-of-line style
#define EOL_UNKNOWN -1 // not defined yet
#define EOL_UNKNOWN (-1) // not defined yet
#define EOL_UNIX 0 // NL
#define EOL_DOS 1 // CR NL
#define EOL_MAC 2 // CR
Expand Down Expand Up @@ -1328,6 +1328,6 @@ enum
};

// Value for b_p_ul indicating the global value must be used.
#define NO_LOCAL_UNDOLEVEL -123456
#define NO_LOCAL_UNDOLEVEL (-123456)

#endif // _OPTION_H_
2 changes: 1 addition & 1 deletion src/regexp.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* In the NFA engine: how many states are allowed
*/
#define NFA_MAX_STATES 100000
#define NFA_TOO_EXPENSIVE -1
#define NFA_TOO_EXPENSIVE (-1)

// Which regexp engine to use? Needed for vim_regcomp().
// Must match with 'regexpengine'.
Expand Down
6 changes: 3 additions & 3 deletions src/spell.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ typedef struct salitem_S

// Values for SP_*ERROR are negative, positive values are used by
// read_cnt_string().
#define SP_TRUNCERROR -1 // spell file truncated error
#define SP_FORMERROR -2 // format error in spell file
#define SP_OTHERERROR -3 // other error while reading spell file
#define SP_TRUNCERROR (-1) // spell file truncated error
#define SP_FORMERROR (-2) // format error in spell file
#define SP_OTHERERROR (-3) // other error while reading spell file

/*
* Structure used in "b_langp", filled from 'spelllang'.
Expand Down
6 changes: 3 additions & 3 deletions src/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2830,7 +2830,7 @@ struct file_buffer
// flags for use of ":lmap" and IM control
long b_p_iminsert; // input mode for insert
long b_p_imsearch; // input mode for search
#define B_IMODE_USE_INSERT -1 // Use b_p_iminsert value for search
#define B_IMODE_USE_INSERT (-1) // Use b_p_iminsert value for search
#define B_IMODE_NONE 0 // Input via none
#define B_IMODE_LMAP 1 // Input via langmap
#define B_IMODE_IM 2 // Input via input method
Expand Down Expand Up @@ -3698,7 +3698,7 @@ struct window_S
winopt_T w_onebuf_opt;
winopt_T w_allbuf_opt;
// transform a pointer to a "onebuf" option into a "allbuf" option
#define GLOBAL_WO(p) ((char *)p + sizeof(winopt_T))
#define GLOBAL_WO(p) ((char *)(p) + sizeof(winopt_T))

// A few options have local flags for P_INSECURE.
#ifdef FEAT_STL_OPT
Expand Down Expand Up @@ -4462,7 +4462,7 @@ typedef struct {
#define FIO_ENCRYPTED 0x1000 // encrypt written bytes
#define FIO_NOCONVERT 0x2000 // skip encoding conversion
#define FIO_UCSBOM 0x4000 // check for BOM at start of file
#define FIO_ALL -1 // allow all formats
#define FIO_ALL (-1) // allow all formats

// When converting, a read() or write() may leave some bytes to be converted
// for the next call. The value is guessed...
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
4639,
/**/
4638,
/**/
Expand Down
58 changes: 29 additions & 29 deletions src/vim.h
Original file line number Diff line number Diff line change
Expand Up @@ -864,9 +864,9 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
#define FINDFILE_DIR 1 // only directories
#define FINDFILE_BOTH 2 // files and directories

#define W_ENDCOL(wp) (wp->w_wincol + wp->w_width)
#define W_ENDCOL(wp) ((wp)->w_wincol + (wp)->w_width)
#ifdef FEAT_MENU
# define W_WINROW(wp) (wp->w_winrow + wp->w_winbar_height)
# define W_WINROW(wp) ((wp)->w_winrow + (wp)->w_winbar_height)
#else
# define W_WINROW(wp) (wp->w_winrow)
#endif
Expand All @@ -887,7 +887,7 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
# define SST_MAX_ENTRIES 1000 // maximal size for state stack array
# define SST_FIX_STATES 7 // size of sst_stack[].
# define SST_DIST 16 // normal distance between entries
# define SST_INVALID (synstate_T *)-1 // invalid syn_state pointer
# define SST_INVALID ((synstate_T *)-1) // invalid syn_state pointer

# define HL_CONTAINED 0x01 // not used on toplevel
# define HL_TRANSP 0x02 // has no highlighting
Expand Down Expand Up @@ -949,7 +949,7 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
#define GETFILE_ERROR 1 // normal error
#define GETFILE_NOT_WRITTEN 2 // "not written" error
#define GETFILE_SAME_FILE 0 // success, same file
#define GETFILE_OPEN_OTHER -1 // success, opened another file
#define GETFILE_OPEN_OTHER (-1) // success, opened another file
#define GETFILE_UNUSED 8
#define GETFILE_SUCCESS(x) ((x) <= 0)

Expand All @@ -971,9 +971,9 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
// Values for "noremap" argument of ins_typebuf(). Also used for
// map->m_noremap and menu->noremap[].
#define REMAP_YES 0 // allow remapping
#define REMAP_NONE -1 // no remapping
#define REMAP_SCRIPT -2 // remap script-local mappings only
#define REMAP_SKIP -3 // no remapping for first char
#define REMAP_NONE (-1) // no remapping
#define REMAP_SCRIPT (-2) // remap script-local mappings only
#define REMAP_SKIP (-3) // no remapping for first char

// Values for mch_call_shell() second argument
#define SHELL_FILTER 1 // filtering text
Expand Down Expand Up @@ -1069,7 +1069,7 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);

// for lnum argument in do_ecmd()
#define ECMD_LASTL (linenr_T)0 // use last position in loaded file
#define ECMD_LAST (linenr_T)-1 // use last position in all files
#define ECMD_LAST ((linenr_T)-1) // use last position in all files
#define ECMD_ONE (linenr_T)1 // use first line

// flags for do_cmdline()
Expand Down Expand Up @@ -1265,13 +1265,13 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
#define MAX_SWAP_PAGE_SIZE 50000

// Special values for current_sctx.sc_sid.
#define SID_MODELINE -1 // when using a modeline
#define SID_CMDARG -2 // for "--cmd" argument
#define SID_CARG -3 // for "-c" argument
#define SID_ENV -4 // for sourcing environment variable
#define SID_ERROR -5 // option was reset because of an error
#define SID_NONE -6 // don't set scriptID
#define SID_WINLAYOUT -7 // changing window size
#define SID_MODELINE (-1) // when using a modeline
#define SID_CMDARG (-2) // for "--cmd" argument
#define SID_CARG (-3) // for "-c" argument
#define SID_ENV (-4) // for sourcing environment variable
#define SID_ERROR (-5) // option was reset because of an error
#define SID_NONE (-6) // don't set scriptID
#define SID_WINLAYOUT (-7) // changing window size

/*
* Events for autocommands.
Expand Down Expand Up @@ -1723,7 +1723,7 @@ void *vim_memset(void *, int, size_t);
// Prefer using emsgf(), because perror() may send the output to the wrong
// destination and mess up the screen.
#ifdef HAVE_STRERROR
# define PERROR(msg) (void)semsg("%s: %s", (char *)msg, strerror(errno))
# define PERROR(msg) (void)semsg("%s: %s", (char *)(msg), strerror(errno))
#else
# define PERROR(msg) do_perror(msg)
#endif
Expand Down Expand Up @@ -1921,7 +1921,7 @@ typedef int sock_T;
(((unsigned)((code) & 0xC0) >> 6) + 1)

#define SET_NUM_MOUSE_CLICKS(code, num) \
(code) = ((code) & 0x3f) | ((((num) - 1) & 3) << 6)
((code) = ((code) & 0x3f) | ((((num) - 1) & 3) << 6))

// Added to mouse column for GUI when 'mousefocus' wants to give focus to a
// window by simulating a click on its status line. We could use up to 128 *
Expand Down Expand Up @@ -2515,8 +2515,8 @@ typedef enum {
#endif

// values for vim_handle_signal() that are not a signal
#define SIGNAL_BLOCK -1
#define SIGNAL_UNBLOCK -2
#define SIGNAL_BLOCK (-1)
#define SIGNAL_UNBLOCK (-2)
#if !defined(UNIX) && !defined(VMS)
# define vim_handle_signal(x) 0
#endif
Expand All @@ -2528,8 +2528,8 @@ typedef enum {

// behavior for bad character, "++bad=" argument
#define BAD_REPLACE '?' // replace it with '?' (default)
#define BAD_KEEP -1 // leave it
#define BAD_DROP -2 // erase it
#define BAD_KEEP (-1) // leave it
#define BAD_DROP (-2) // erase it

// last argument for do_source()
#define DOSO_NONE 0
Expand All @@ -2552,11 +2552,11 @@ typedef enum {
// direction for nv_mousescroll() and ins_mousescroll()
#define MSCR_DOWN 0 // DOWN must be FALSE
#define MSCR_UP 1
#define MSCR_LEFT -1
#define MSCR_RIGHT -2
#define MSCR_LEFT (-1)
#define MSCR_RIGHT (-2)

#define KEYLEN_PART_KEY -1 // keylen value for incomplete key-code
#define KEYLEN_PART_MAP -2 // keylen value for incomplete mapping
#define KEYLEN_PART_KEY (-1) // keylen value for incomplete key-code
#define KEYLEN_PART_MAP (-2) // keylen value for incomplete mapping
#define KEYLEN_REMOVED 9999 // keylen value for removed sequence

// Return values from win32_fileinfo().
Expand Down Expand Up @@ -2716,8 +2716,8 @@ typedef enum {

#if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H)
# define ELAPSED_TIMEVAL
# define ELAPSED_INIT(v) gettimeofday(&v, NULL)
# define ELAPSED_FUNC(v) elapsed(&v)
# define ELAPSED_INIT(v) gettimeofday(&(v), NULL)
# define ELAPSED_FUNC(v) elapsed(&(v))
typedef struct timeval elapsed_T;
long elapsed(struct timeval *start_tv);
#elif defined(MSWIN)
Expand All @@ -2734,8 +2734,8 @@ long elapsed(DWORD start_tick);
#endif

// Replacement for nchar used by nv_replace().
#define REPLACE_CR_NCHAR -1
#define REPLACE_NL_NCHAR -2
#define REPLACE_CR_NCHAR (-1)
#define REPLACE_NL_NCHAR (-2)

// flags for term_start()
#define TERM_START_NOJOB 1
Expand Down
6 changes: 3 additions & 3 deletions src/vim9.h
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,10 @@ struct dfunc_S {
extern garray_T def_functions;

// Used for "lnum" when a range is to be taken from the stack.
#define LNUM_VARIABLE_RANGE -999
#define LNUM_VARIABLE_RANGE (-999)

// Used for "lnum" when a range is to be taken from the stack and "!" is used.
#define LNUM_VARIABLE_RANGE_ABOVE -888
#define LNUM_VARIABLE_RANGE_ABOVE (-888)

// Keep in sync with get_compile_type()
#ifdef FEAT_PROFILE
Expand All @@ -530,7 +530,7 @@ extern garray_T def_functions;
: (dfunc)->df_instr))
#else
# define INSTRUCTIONS(dfunc) \
(debug_break_level > 0 || may_break_in_function(dfunc->df_ufunc) \
(debug_break_level > 0 || may_break_in_function((dfunc)->df_ufunc) \
? (dfunc)->df_instr_debug \
: (dfunc)->df_instr)
#endif
Expand Down

0 comments on commit 9dac9b1

Please sign in to comment.