Hi Sergei,

On Mon, 2024-07-15 at 22:23 +0100, Sergei Trofimovich wrote:
> `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"
>           |           ^~~~

OK, I see why you want to warn for this. There is a real chance you use
those char array's with some str functions and then there is trouble.

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

With initialize with individual bytes you mean:

diff --git a/backends/i386_regs.c b/backends/i386_regs.c
index 7ec93bb9fc13..ead55ef7f931 100644
--- a/backends/i386_regs.c
+++ b/backends/i386_regs.c
@@ -85,7 +85,15 @@ i386_register_info (Ebl *ebl __attribute__
((unused)),
     {
       static const char baseregs[][2] =
        {
-         "ax", "cx", "dx", "bx", "sp", "bp", "si", "di", "ip"
+         {'a', 'x'},
+         {'c', 'x'},
+         {'d', 'x'},
+         {'b', 'x'},
+         {'s', 'p'},
+         {'b', 'p'},
+         {'s', 'i'},
+         {'d', 'i'},
+         {'i', 'p'},
        };
 
     case 4:

?

Since the use of this array is basically just:

      name[0] = 'r';
      name[1] = baseregs[regno][0];
      name[2] = baseregs[regno][1];

I think I prefer the individual bytes init way. It makes more clear
what we really use these arrays for. imho.

Thanks,

Mark

Reply via email to