A similar macro is defined in the Linux kernel [1].
To refactor the code I used a slightly modified Coccinelle script I found in
[2].
```diff
// Use the macro ARRAY_SIZE when possible
//
// Confidence: High
// Copyright: (C) Gilles Muller, Julia Lawall, EMN, DIKU. GPLv2.
// URL: http://www.emn.fr/x-info/coccinelle/rules/array.html
// Options: -I ... -all_includes can give more complete results
@@
type T;
T[] E;
@@
- (sizeof(E)/sizeof(*E))
+ ARRAY_SIZE(E)
@@
type T;
T[] E;
@@
- (sizeof(E)/sizeof(E[...]))
+ ARRAY_SIZE(E)
@@
type T;
T[] E;
@@
- (sizeof(E)/sizeof(T))
+ ARRAY_SIZE(E)
@n@
identifier AS,E;
@@
- #define AS(E) ARRAY_SIZE(E)
@@
expression E;
identifier n.AS;
@@
- AS(E)
+ ARRAY_SIZE(E)
```
`spatch --in-place --sp-file array_size.cocci -I src/ -I build/include/ -I build/src/nvim/auto/ src/nvim/*.c`
[1] http://lxr.free-electrons.com/source/include/linux/kernel.h#L54
[2] http://www.emn.fr/z-info/coccinelle/rules/#macros
Get prefix to a -D_FORTIFY_SOURCE string if it is present in
CFLAGS and apply the prefix to flags added to redefine
_FORTIFY_SOURCE in CFLAGS and CPPFLAGS
* fixes 1569
Problem : Dereference of null pointer @ 1980.
Diagnostic : False positive.
Rationale : I haven't been able to find the real reason why this is
signaled. Nonetheless, I've been able to track down the
introduction of this warning to commit
77135447e0.
The change there affecting this function is just a
transformation maintaining semantics. So, this must be a
FP, though I can't explain why.
Analyzer thinks `win->w_buffer` can be null in line 1980,
following an error path assuming win->w_buffer null at line
1819. Given that `win_close` function was not modified by
mentioned commit, I don't understand why this path is
analyzed after the changes, but not before them. Or if it's
analyzed, why it's discarded before changes but not after
them. I don't see anything in changes to
`close_last_window_tabpage` that should affect to
being able to deduce `win->w_buffer` is not null.
Resolution : Assert buffer not null in `win_close_othertab`.
Function comments state that passed window should have a
buffer that can be hidden, which implies there should be a
buffer.
Reverting changes to `close_last_window_tabpage` in
mentioned commit would be another way to fix this (tried
and worked).
But assert is preferred in this case because flat style
reads better and we have some other way to fix it.
Problem : Double free @ 5213.
Diagnostic : False positive.
Rationale : I haven't been able to find the real reason why this is
signaled. Nonetheless, I've been able to track down the
introduction of this warning to commit
77135447e0.
The change there affecting this function is just a
transformation maintaining semantics. So, this must be a
FP, though I can't explain why.
Resolution : Revert changes in mentioned commmit touching this function.
Problems : Dereference of null pointer @ 6251.
Dereference of null pointer @ 6267.
Dereference of null pointer @ 6351.
Diagnostic : False positive.
Rationale : Problems occur if varp is null after
`varp = get_varp_scope(p, opt_flags);`.
That can only happen if option is hidden. Those are options
that can be set (for backwards compatibility reasons) but
that do nothing (see `:h hidden-options`,
`:h missing-options`). In particular, even if setting them
is allowed, value is not stored, so these options have no
real value.
So, suggested error paths should not occur, as checks
comparing option value and default value should discard
them.
Resolution : We could just `assert(varp)` before line 6235
`varp_local = varp;`. That was tried and worked.
But we prefer modifying the code to explicitly skip hidden
options.
A redundant `!istermoption(p)` is removed too (it's already
checked by for loop condition).
Problem : Exlicit null dereferenced (FORWARD NULL) @ 2859.
Diagnostic : Real issue.
Rationale : Code within `if (!p_bk)` seems to assume `backup` not null
at that point, which may not be true.
Resolution : Don't enter conditional on null `backup`.
FALSE was being used instead of FAIL.
They happen to have the same value, so it works the same.
But from function comment it's clear it uses the OK/FAIL convention.
Problem : Unchecked return value (CHECKED_RETURN) @ 2644.
Diagnostic : Real issue.
Rationale : Other `u_save` invocations are checked, and there's no
reason to think this invocation could not fail.
Resolution : Check and return if failed (other previous checks in the
same function just return, without reporting error, so
we just do the same).
Problem : Unchecked return value (CHECKED_RETURN) @ 8554.
Diagnostic : Real issue.
Rationale : Other invocations of `do_source` are checked and generate
an error message if fail. There seems to be no reason why
this particular instance could not fail the same.
Resolution : Check invocation and generate error message on failure.
It turns out the check was being performed without optimizations enabled
even when the CMAKE_BUILD_TYPE was set to a release build. This led to
_FORTIFY_SOURCE's level not being correctly determined, and us failing
to apply the correct workaround.
To counter this, we'll take the default flags for the build type and
apply them. Also, if options are passed via CFLAGS, they are
automatically passed on to the underlying build. So this should cover
all the necessary ground.
This fixes#1647.
- Caller can override bundled dependency location using
DEPS_PREFIX
- Cache variable DEPS_PREFIX, using .deps/usr by default
- Removed unused variables DEPS_BIN_DIR, DEPS_BUILD_DIR, DEPS_DIR
DEPS_INSTALL_DIR
- Corner case: if the caller tries to override DEPS_PREFIX after a
successful cmake configuration, the caller needs to clear the cache
because dependency checks are based on the old value
- third-party is built under .deps by default instead of using its own
${CMAKE_BINARY_DIR}, move this default setting out of the cmake
settings and into the Makefile.
- As a consequence the workflow of building third-party using CMake
should feel more natural, avoid the additional folder or setting
DEPS_DIR from the command line.
- This commit does not change the default behaviour when calling the
Makefile wrapper.
Problem : Array access (via field 'y_array') results in a null pointer
dereference @ 4487.
Diagnostic : Real issue.
Rationale : If the array was previously freed and the size of the array
(y_current->y_size) was not updated to zero, the loop @4486
could be entered and a NULL pointer would be dereferenced.
Resolution : Use free_yank_all() to take care of the NULL check and
to free the current yank register.
Adapt #1533 and #1596 to conform to upstream patch
(https://groups.google.com/forum/#!topic/vim_dev/vp0Lwo9f56s).
Problem: Since patch 7.4.232 "1,3s/\n//" joins two lines instead of
three.
(Eliseo Martínez) Issue 287
Solution: Correct the line count. (Christian Brabandt)
Also set the last used search pattern.