Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:23
erlang
7071-erts-Use-C99-style-flexible-array-for-envi...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 7071-erts-Use-C99-style-flexible-array-for-environment-in.patch of Package erlang
From 5776ef37e4b3667e50cf9a2df154ac71f2ccb48b Mon Sep 17 00:00:00 2001 From: Frej Drejhammar <frej.drejhammar@gmail.com> Date: Thu, 6 Apr 2023 11:23:23 +0200 Subject: [PATCH] erts: Use C99-style flexible array for environment in ErlFunThing Consider the code fragment from erts/emulator/beam/erl_math.c below: ``` Eterm tmp_hp[ERL_FUN_SIZE]; ErlFunThing *funp; funp = (ErlFunThing*)tmp_hp; funp->thing_word = HEADER_FUN; funp->entry.exp = NULL; ``` As `ErlFunThing` is not using a C99-style flexible array, GCC 12 is smart enough to figure out that `sizeof(*funp)` is larger than sizeof(tmp_hp) as ERL_FUN_SIZE subtracts the word used for the 1-sized environment array in `ErlFunThing`. The difference in size leads to multiple warnings in the style of: `array subscript ErlFunThing {aka struct erl_fun_thing}[0] is partly outside array bounds of Eterm[5]`. We can avoid the warning by converting the `env`-field in `ErlFunThing` to a flexible array and then remove the `-1` from the definition of `ERL_FUN_SIZE`. The runtime is already using C99-style flexible arrays for microstate accounting, in `erl_lock_count.h` and a comment in `erts/emulator/beam/erl_math.c` documents a requirement for a C99-capable compiler. Hopefully this is enough to not inadvertently break compilation with older compilers. --- erts/emulator/beam/erl_fun.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/erts/emulator/beam/erl_fun.h b/erts/emulator/beam/erl_fun.h index 43f3ec3b22..a67afaceeb 100644 --- a/erts/emulator/beam/erl_fun.h +++ b/erts/emulator/beam/erl_fun.h @@ -57,11 +57,12 @@ typedef struct erl_fun_thing { Uint num_free; /* Number of free variables (in env). */ /* -- The following may be compound Erlang terms ---------------------- */ Eterm creator; /* Pid of creator process (contains node). */ - Eterm env[1]; /* Environment (free variables). */ + Eterm env[]; /* Environment (free variables). */ } ErlFunThing; -/* ERL_FUN_SIZE does _not_ include space for the environment */ -#define ERL_FUN_SIZE ((sizeof(ErlFunThing)/sizeof(Eterm))-1) +/* ERL_FUN_SIZE does _not_ include space for the environment which is a + * C99-style flexible array */ +#define ERL_FUN_SIZE ((sizeof(ErlFunThing)/sizeof(Eterm))) void erts_init_fun_table(void); void erts_fun_info(fmtfn_t, void *); -- 2.35.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor