aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt21
-rw-r--r--src/nvim/ex_docmd.c4
-rw-r--r--src/nvim/fileio.c32
-rw-r--r--src/nvim/mbyte.c16
-rw-r--r--src/nvim/ops.c12
-rw-r--r--src/nvim/option.c13
-rw-r--r--src/nvim/syntax.c29
-rw-r--r--src/nvim/undo.c2
-rw-r--r--src/nvim/version.c46
-rw-r--r--src/nvim/window.c1
10 files changed, 99 insertions, 77 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fd5f51ccc8..42eb50ac43 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -70,6 +70,17 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion")
# does not work with Neovim due to some uses of dynamically-sized structures.
# See https://github.com/neovim/neovim/issues/223 for details.
include(CheckCSourceCompiles)
+
+# Include the build type's default flags in the check for _FORTIFY_SOURCE,
+# otherwise we may incorrectly identify the level as acceptable and find out
+# later that it was not when optimizations were enabled. CFLAGS is applied
+# even though you don't see it in CMAKE_REQUIRED_FLAGS.
+set(INIT_FLAGS_NAME CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE})
+string(TOUPPER ${INIT_FLAGS_NAME} INIT_FLAGS_NAME)
+if(${INIT_FLAGS_NAME})
+ set(CMAKE_REQUIRED_FLAGS "${${INIT_FLAGS_NAME}}")
+endif()
+
check_c_source_compiles("
#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 1
#error \"_FORTIFY_SOURCE > 1\"
@@ -82,10 +93,16 @@ main(void)
" _FORTIFY_SOURCE_ACCEPTABLE)
if(NOT _FORTIFY_SOURCE_ACCEPTABLE)
+ # Extract possible prefix to _FORTIFY_SOURCE (e.g. -Wp,-D_FORTIFY_SOURCE).
+ STRING(REGEX MATCH "[^\ ]+-D_FORTIFY_SOURCE" _FORTIFY_SOURCE_PREFIX "${CMAKE_C_FLAGS}")
+ STRING(REPLACE "-D_FORTIFY_SOURCE" "" _FORTIFY_SOURCE_PREFIX "${_FORTIFY_SOURCE_PREFIX}" )
+ if (NOT _FORTIFY_SOURCE_PREFIX STREQUAL "")
+ message(STATUS "Detected _FORTIFY_SOURCE Prefix=${_FORTIFY_SOURCE_PREFIX}")
+ endif()
# -U in add_definitions doesn't end up in the correct spot, so we add it to
# the flags variable instead.
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FORTIFY_SOURCE_PREFIX}-U_FORTIFY_SOURCE ${_FORTIFY_SOURCE_PREFIX}-D_FORTIFY_SOURCE=1")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_FORTIFY_SOURCE_PREFIX}-U_FORTIFY_SOURCE ${_FORTIFY_SOURCE_PREFIX}-D_FORTIFY_SOURCE=1")
endif()
add_definitions(-Wall -Wextra -pedantic -Wno-unused-parameter
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 56c8206d2a..65a0017e20 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -8543,7 +8543,9 @@ static void ex_loadview(exarg_T *eap)
fname = get_view_file(*eap->arg);
if (fname != NULL) {
- do_source(fname, FALSE, DOSO_NONE);
+ if (do_source(fname, FALSE, DOSO_NONE) == FAIL) {
+ EMSG2(_(e_notopen), fname);
+ }
free(fname);
}
}
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index 9734ac07f9..9c6d7c96bb 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -2839,27 +2839,25 @@ buf_write (
* Check if backup file already exists.
*/
if (os_fileinfo((char *)backup, &file_info_new)) {
- /*
- * Check if backup file is same as original file.
- * May happen when modname() gave the same file back (e.g. silly
- * link). If we don't check here, we either ruin the file when
- * copying or erase it after writing.
- */
if (os_fileinfo_id_equal(&file_info_new, &file_info_old)) {
+ /*
+ * Backup file is same as original file.
+ * May happen when modname() gave the same file back (e.g. silly
+ * link). If we don't check here, we either ruin the file when
+ * copying or erase it after writing.
+ */
free(backup);
backup = NULL; /* no backup file to delete */
- }
-
- /*
- * If we are not going to keep the backup file, don't
- * delete an existing one, try to use another name.
- * Change one character, just before the extension.
- */
- if (!p_bk) {
- wp = backup + STRLEN(backup) - 1
- - STRLEN(backup_ext);
- if (wp < backup) /* empty file name ??? */
+ } else if (!p_bk) {
+ /*
+ * We are not going to keep the backup file, so don't
+ * delete an existing one, and try to use another name instead.
+ * Change one character, just before the extension.
+ */
+ wp = backup + STRLEN(backup) - 1 - STRLEN(backup_ext);
+ if (wp < backup) { /* empty file name ??? */
wp = backup;
+ }
*wp = 'z';
while (*wp > 'a'
&& os_fileinfo((char *)backup, &file_info_new)) {
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index 9b4513e979..db4516527a 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -162,7 +162,7 @@ static char utf8len_tab_zero[256] =
* "iso-8859-n" is handled by enc_canonize() directly.
*/
static struct
-{ char *name; int prop; int codepage; }
+{ const char *name; int prop; int codepage; }
enc_canon_table[] =
{
#define IDX_LATIN_1 0
@@ -300,7 +300,7 @@ enc_canon_table[] =
* Aliases for encoding names.
*/
static struct
-{ char *name; int canon; }
+{ const char *name; int canon; }
enc_alias_table[] =
{
{"ansi", IDX_LATIN_1},
@@ -374,7 +374,7 @@ enc_alias_table[] =
* Find encoding "name" in the list of canonical encoding names.
* Returns -1 if not found.
*/
-static int enc_canon_search(char_u *name)
+static int enc_canon_search(const char_u *name)
{
int i;
@@ -390,7 +390,7 @@ static int enc_canon_search(char_u *name)
* Find canonical encoding "name" in the list and return its properties.
* Returns 0 if not found.
*/
-int enc_canon_props(char_u *name)
+int enc_canon_props(const char_u *name)
{
int i;
@@ -667,12 +667,12 @@ void remove_bom(char_u *s)
* 2 for an (ASCII) word character
* >2 for other word characters
*/
-int mb_get_class(char_u *p)
+int mb_get_class(const char_u *p)
{
return mb_get_class_buf(p, curbuf);
}
-int mb_get_class_buf(char_u *p, buf_T *buf)
+int mb_get_class_buf(const char_u *p, buf_T *buf)
{
if (MB_BYTE2LEN(p[0]) == 1) {
if (p[0] == NUL || vim_iswhite(p[0]))
@@ -927,7 +927,7 @@ static int dbcs_ptr2len_len(const char_u *p, int size)
/*
* Return true if "c" is in "table[size / sizeof(struct interval)]".
*/
-static bool intable(struct interval *table, size_t size, int c)
+static bool intable(const struct interval *table, size_t size, int c)
{
int mid, bot, top;
@@ -3570,7 +3570,7 @@ static char_u * iconv_string(vimconv_T *vcp, char_u *str, int slen, int *unconvl
if ((*mb_ptr2cells)((char_u *)from) > 1)
*to++ = '?';
if (enc_utf8)
- l = utfc_ptr2len_len((char_u *)from, (int)fromlen);
+ l = utfc_ptr2len_len((const char_u *)from, (int)fromlen);
else {
l = (*mb_ptr2len)((char_u *)from);
if (l > (int)fromlen)
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index 9f73d40761..931b877a95 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -30,6 +30,7 @@
#include "nvim/fold.h"
#include "nvim/getchar.h"
#include "nvim/indent.h"
+#include "nvim/log.h"
#include "nvim/mark.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
@@ -2641,7 +2642,10 @@ do_put (
/* Autocommands may be executed when saving lines for undo, which may make
* y_array invalid. Start undo now to avoid that. */
- u_save(curwin->w_cursor.lnum, curwin->w_cursor.lnum + 1);
+ if (u_save(curwin->w_cursor.lnum, curwin->w_cursor.lnum + 1) == FAIL) {
+ ELOG(_("Failed to save undo information"));
+ return;
+ }
if (insert_string != NULL) {
y_type = MCHAR;
@@ -4483,10 +4487,7 @@ int read_viminfo_register(vir_T *virp, int force)
if (set_prev)
y_previous = y_current;
- for (int i = 0; i < y_current->y_size; i++) {
- free(y_current->y_array[i]);
- }
- free(y_current->y_array);
+ free_yank_all();
array = xmalloc(limit * sizeof(char_u *));
str = skipwhite(skiptowhite(str));
@@ -4515,7 +4516,6 @@ int read_viminfo_register(vir_T *virp, int force)
if (do_it) {
if (size == 0) {
free(array);
- y_current->y_array = NULL;
} else if (size < limit) {
y_current->y_array = xrealloc(array, size * sizeof(char_u *));
} else {
diff --git a/src/nvim/option.c b/src/nvim/option.c
index c1ab3f2ee5..2b3c87511e 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -6196,15 +6196,17 @@ int makeset(FILE *fd, int opt_flags, int local_only)
int pri;
/*
- * The options that don't have a default (terminal name, columns, lines)
- * are never written. Terminal options are also not written.
+ * Some options are never written:
+ * - Options that don't have a default (terminal name, columns, lines).
+ * - Terminal options.
+ * - Hidden options.
+ *
* Do the loop over "options[]" twice: once for options with the
* P_PRI_MKRC flag and once without.
*/
for (pri = 1; pri >= 0; --pri) {
for (p = &options[0]; !istermoption(p); p++)
if (!(p->flags & P_NO_MKRC)
- && !istermoption(p)
&& ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0))) {
/* skip global option when only doing locals */
if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
@@ -6215,8 +6217,11 @@ int makeset(FILE *fd, int opt_flags, int local_only)
if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
continue;
- /* Global values are only written when not at the default value. */
varp = get_varp_scope(p, opt_flags);
+ /* Hidden options are never written. */
+ if (!varp)
+ continue;
+ /* Global values are only written when not at the default value. */
if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
continue;
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index b7a485598b..3deda0a8c9 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -5157,22 +5157,21 @@ get_id_list (
regmatch.rm_ic = TRUE;
id = 0;
for (int i = highlight_ga.ga_len; --i >= 0; ) {
- if (!vim_regexec(&regmatch, HL_TABLE()[i].sg_name, (colnr_T)0)) {
- continue;
- }
- if (round == 2) {
- /* Got more items than expected; can happen
- * when adding items that match:
- * "contains=a.*b,axb".
- * Go back to first round */
- if (count >= total_count) {
- free(retval);
- round = 1;
- } else
- retval[count] = i + 1;
+ if (vim_regexec(&regmatch, HL_TABLE()[i].sg_name, (colnr_T)0)) {
+ if (round == 2) {
+ /* Got more items than expected; can happen
+ * when adding items that match:
+ * "contains=a.*b,axb".
+ * Go back to first round */
+ if (count >= total_count) {
+ free(retval);
+ round = 1;
+ } else
+ retval[count] = i + 1;
+ }
+ ++count;
+ id = -1; /* remember that we found one */
}
- ++count;
- id = -1; /* remember that we found one */
}
vim_regfree(regmatch.regprog);
}
diff --git a/src/nvim/undo.c b/src/nvim/undo.c
index 2ab31b6cfd..9a3da5bcdb 100644
--- a/src/nvim/undo.c
+++ b/src/nvim/undo.c
@@ -230,7 +230,7 @@ int u_save(linenr_T top, linenr_T bot)
if (top > curbuf->b_ml.ml_line_count
|| top >= bot
|| bot > curbuf->b_ml.ml_line_count + 1)
- return FALSE; /* rely on caller to do error messages */
+ return FAIL; /* rely on caller to do error messages */
if (top + 2 == bot)
u_saveline((linenr_T)(top + 1));
diff --git a/src/nvim/version.c b/src/nvim/version.c
index f0f00deea4..3460b7c6c3 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -182,21 +182,21 @@ static int included_patches[] = {
//551,
//550,
//549,
- //548,
+ //548 NA
//547,
//546,
//545,
- //544,
+ //544 NA
543,
//542,
//541,
- //540,
+ //540 NA
//539,
//538,
//537,
//536,
//535,
- //534,
+ //534 NA
//533,
//532,
//531,
@@ -207,7 +207,7 @@ static int included_patches[] = {
//526,
//525,
//524,
- //523,
+ //523 NA
//522,
//521,
//520,
@@ -218,24 +218,24 @@ static int included_patches[] = {
//515,
//514,
//513,
- //512,
- //511,
- //510,
+ //512 NA
+ //511 NA
+ //510 NA
//509,
//508,
- //507,
- //506,
- //505,
- //504,
+ //507 NA
+ //506 NA
+ //505 NA
+ //504 NA
//503,
//502,
- //501,
+ //501 NA
//500,
//499,
- //498,
+ //498 NA
//497,
- //496,
- //495,
+ //496 NA
+ //495 NA
//494,
//493,
//492,
@@ -246,7 +246,7 @@ static int included_patches[] = {
//487,
//486,
//485,
- //484,
+ //484 NA
//483,
//482 NA
//481 NA
@@ -270,7 +270,7 @@ static int included_patches[] = {
//462,
//461 NA
//460 NA
- //459,
+ //459 NA
//458,
//457,
//456,
@@ -281,7 +281,7 @@ static int included_patches[] = {
//451,
//450,
//449,
- //448,
+ //448 NA
//447,
//446,
//445,
@@ -344,7 +344,7 @@ static int included_patches[] = {
388,
387,
386,
- //385,
+ //385 NA
//384 NA
383,
382,
@@ -474,8 +474,8 @@ static int included_patches[] = {
//258 NA
//257 NA
256,
- //255,
- //254,
+ //255 NA
+ //254 NA
253,
//252 NA
251,
@@ -483,7 +483,7 @@ static int included_patches[] = {
249,
248,
247,
- //246,
+ //246 NA
245,
//244,
243,
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 0ed43b0184..029fcaac8b 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -1977,6 +1977,7 @@ void win_close_othertab(win_T *win, int free_buf, tabpage_T *tp)
tabpage_T *ptp = NULL;
int free_tp = FALSE;
+ assert(win->w_buffer); // to avoid np dereference warning in next line
if (win->w_closing || win->w_buffer->b_closing)
return; /* window is already being closed */