]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1692: global_functions are not constant v9.1.1692
authorDamien Lejay <damien@lejay.be>
Tue, 26 Aug 2025 19:03:31 +0000 (21:03 +0200)
committerChristian Brabandt <cb@256bit.org>
Tue, 26 Aug 2025 19:03:31 +0000 (21:03 +0200)
Problem:  global_functions are not constant
Solution: Place global_functions[] in read-only memory (Damien Lejay).

Mark global_functions[] as `static const`.  The table is never modified
at runtime, so keeping it in writable `.data` has no benefit.

Only a local pointer in func_check_arg_types() needed adjusting to
`const`.  No functional changes.

closes: #18121

Signed-off-by: Damien Lejay <damien@lejay.be>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/evalfunc.c
src/testdir/test_function_lists.vim
src/version.c

index 13f1823d3b83f3cf99456405b5cf2c2175d03cfd..3a0e9a77af0079170e91d026a44e26212e58f0dc 100644 (file)
@@ -1934,7 +1934,7 @@ typedef struct
 # define TERM_FUNC(name) NULL
 #endif
 
-static funcentry_T global_functions[] =
+static const funcentry_T global_functions[] =
 {
     {"abs",            1, 1, FEARG_1,      arg1_float_or_nr,
                        ret_any,            f_abs},
@@ -3360,7 +3360,7 @@ internal_func_check_arg_types(
                return FAIL;
     }
 
-    argcheck_T *argchecks = global_functions[idx].f_argcheck;
+    const argcheck_T   *argchecks = global_functions[idx].f_argcheck;
 
     if (argchecks == NULL)
        return OK;
index dd69b832608d069673ed05ce81e9502145818d9a..bd79f7717fecfab0a3280f2947f7eeeda0ad616f 100644 (file)
@@ -17,7 +17,7 @@ func Test_function_lists()
   " Create a file of the functions in evalfunc.c:global_functions[].
   enew!
   read ../evalfunc.c
-  1,/^static funcentry_T global_functions\[\] =$/d
+  1,/^static const funcentry_T global_functions\[\] =$/d
   call search('^};$')
   .,$d
   v/^    {/d
@@ -38,7 +38,7 @@ func Test_function_lists()
   " not obsolete, sorted in ASCII order.
   enew!
   read ../evalfunc.c
-  1,/^static funcentry_T global_functions\[\] =$/d
+  1,/^static const funcentry_T global_functions\[\] =$/d
   call search('^};$')
   .,$d
   v/^    {/d
index db3a4b7ac35c299bc16b4463f6c933eeb153706a..ec3bcc5deca19a3801e34a2cfcee696974bf29fe 100644 (file)
@@ -724,6 +724,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1692,
 /**/
     1691,
 /**/