[PATCH] backends: allocate enough stace for null terminator

Sergei Trofimovich slyich@gmail.com
Mon Jul 15 21:23:40 GMT 2024


`gcc-15` added a new warning in https://gcc.gnu.org/PR115185:

    i386_regs.c:88:11: error: initializer-string for array of 'char' is too long [-Werror=unterminated-string-initialization]
       88 |           "ax", "cx", "dx", "bx", "sp", "bp", "si", "di", "ip"
          |           ^~~~

`elfutils` does not need to store '\0'. We could either initialize the
arrays with individual bytes or allocate extra byte for null.

This change allocates extra byte per string to fit in null terminator.

	* backends/i386_regs.c (i386_register_info): Add extra byte per
	entry to fix gcc-15 warning.
	* backends/x86_64_regs.c (x86_64_register_info): Ditto.

Signed-off-by: Sergei Trofimovich <slyich@gmail.com>
---
 backends/i386_regs.c   | 2 +-
 backends/x86_64_regs.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/backends/i386_regs.c b/backends/i386_regs.c
index 7ec93bb9..4bca1b1a 100644
--- a/backends/i386_regs.c
+++ b/backends/i386_regs.c
@@ -83,7 +83,7 @@ i386_register_info (Ebl *ebl __attribute__ ((unused)),
 
   switch (regno)
     {
-      static const char baseregs[][2] =
+      static const char baseregs[][3] =
 	{
 	  "ax", "cx", "dx", "bx", "sp", "bp", "si", "di", "ip"
 	};
diff --git a/backends/x86_64_regs.c b/backends/x86_64_regs.c
index ef987daf..c92c862a 100644
--- a/backends/x86_64_regs.c
+++ b/backends/x86_64_regs.c
@@ -80,7 +80,7 @@ x86_64_register_info (Ebl *ebl __attribute__ ((unused)),
 
   switch (regno)
     {
-      static const char baseregs[][2] =
+      static const char baseregs[][3] =
 	{
 	  "ax", "dx", "cx", "bx", "si", "di", "bp", "sp"
 	};
-- 
2.45.2



More information about the Elfutils-devel mailing list