Commit: patch 9.2.0650: Vim aborts at startup when built with the example -O2 CFLAGS

1 view
Skip to first unread message

Christian Brabandt

unread,
2:45 PM (7 hours ago) 2:45 PM
to vim...@googlegroups.com
patch 9.2.0650: Vim aborts at startup when built with the example -O2 CFLAGS

Commit: https://github.com/vim/vim/commit/dd4fbdb392e72097a67da20838216d9b9600363b
Author: Hirohito Higashi <h.eas...@gmail.com>
Date: Mon Jun 15 18:20:15 2026 +0000

patch 9.2.0650: Vim aborts at startup when built with the example -O2 CFLAGS

Problem: Building with an optimizing example CFLAGS line in src/Makefile
(which bypasses configure) aborts Vim at startup with a buffer
overflow, because the compiler then defaults _FORTIFY_SOURCE to
a level >= 2 (user202729)
Solution: Define FORTIFY_CFLAGS with -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
and reference it from the optimizing example CFLAGS lines, the
same pin configure already applies; at higher levels the check
false-positives on the "x[1] but actually longer" struct-hack
arrays.

fixes: #20526
closes: #20530

Co-Authored-By: Claude Opus 4.8 (1M context) <nor...@anthropic.com>
Signed-off-by: Hirohito Higashi <h.eas...@gmail.com>
Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/Makefile b/src/Makefile
index 1a6fa1c66..f66d94f1a 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -597,13 +597,19 @@ CClink = $(CC)
#CFLAGS = -O -Olimit 2000
#CFLAGS = -O -FOlimit,2000

+# Add $(FORTIFY_CFLAGS) to optimizing example lines below: at higher levels
+# (the compiler default with -O) the buffer overflow check aborts Vim on the
+# "x[1] but actually longer" struct-hack arrays (e.g. dictitem di_key).
+# configure adds this automatically; these examples bypass it.
+FORTIFY_CFLAGS = -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
+
# Often used for GCC: mixed optimizing, lot of optimizing, debugging
-#CFLAGS = -g -O2 -fno-strength-reduce -Wall -Wshadow -Wmissing-prototypes
-#CFLAGS = -g -O2 -fno-strength-reduce -Wall -Wmissing-prototypes
+#CFLAGS = -g -O2 -fno-strength-reduce -Wall -Wshadow -Wmissing-prototypes $(FORTIFY_CFLAGS)
+#CFLAGS = -g -O2 -fno-strength-reduce -Wall -Wmissing-prototypes $(FORTIFY_CFLAGS)
#CFLAGS = -g -Wall -Wmissing-prototypes
-#CFLAGS = -O6 -fno-strength-reduce -Wall -Wshadow -Wmissing-prototypes
+#CFLAGS = -O6 -fno-strength-reduce -Wall -Wshadow -Wmissing-prototypes $(FORTIFY_CFLAGS)
#CFLAGS = -g -DDEBUG -Wall -Wshadow -Wmissing-prototypes
-#CFLAGS = -g -O2 '-DSTARTUPTIME="vimstartup"' -fno-strength-reduce -Wall -Wmissing-prototypes
+#CFLAGS = -g -O2 '-DSTARTUPTIME="vimstartup"' -fno-strength-reduce -Wall -Wmissing-prototypes $(FORTIFY_CFLAGS)

# Use this with GCC to check for mistakes, unused arguments, etc.
# Note: If you use -Wextra and get warnings in GTK code about function
diff --git a/src/version.c b/src/version.c
index 392bae84c..ff26c4350 100644
--- a/src/version.c
+++ b/src/version.c
@@ -759,6 +759,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 650,
/**/
649,
/**/
Reply all
Reply to author
Forward
0 new messages