[PATCH] gdbstub: Make generated compound literal array size explicit

Philippe Mathieu-Daudé posted 1 patch 1 month, 3 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260216214332.47639-1-philmd@linaro.org
Maintainers: "Alex Bennée" <alex.bennee@linaro.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, John Snow <jsnow@redhat.com>, Cleber Rosa <crosa@redhat.com>
scripts/feature_to_c.py | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
[PATCH] gdbstub: Make generated compound literal array size explicit
Posted by Philippe Mathieu-Daudé 1 month, 3 weeks ago
GDBFeature::num_regs holds the number of registers, but when using
the compound literal construction, if the last array entry is not
set, the array will be shorter. Prevent array overrun by making the
array length explicit,

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 scripts/feature_to_c.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/scripts/feature_to_c.py b/scripts/feature_to_c.py
index 807af0e685c..3aa62fb895f 100644
--- a/scripts/feature_to_c.py
+++ b/scripts/feature_to_c.py
@@ -90,13 +90,16 @@ def writeliteral(indent, bytes):
     writeliteral(8, read)
     sys.stdout.write(',\n')
     writeliteral(8, bytes(feature_name, 'utf-8'))
-    sys.stdout.write(',\n        (const char * const []) {\n')
+    sys.stdout.write(',\n')
+    sys.stdout.write(f'        (const char * const [{num_regs}]) {{\n')
 
     for index, regname in enumerate(regnames):
         sys.stdout.write(f'            [{regnums[index] - base_reg}] =\n')
         writeliteral(16, bytes(regname, 'utf-8'))
         sys.stdout.write(',\n')
 
-    sys.stdout.write(f'        }},\n        {num_regs},\n    }},\n')
+    sys.stdout.write( '        },\n')
+    sys.stdout.write(f'        {num_regs},\n')
+    sys.stdout.write( '    },\n')
 
 sys.stdout.write('    { NULL }\n};\n')
-- 
2.52.0


Re: [PATCH] gdbstub: Make generated compound literal array size explicit
Posted by Akihiko Odaki 1 month, 3 weeks ago
On 2026/02/17 6:43, Philippe Mathieu-Daudé wrote:
> GDBFeature::num_regs holds the number of registers, but when using
> the compound literal construction, if the last array entry is not
> set, the array will be shorter. Prevent array overrun by making the
> array length explicit,
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Reviewed-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>

Re: [PATCH] gdbstub: Make generated compound literal array size explicit
Posted by Richard Henderson 1 month, 3 weeks ago
On 2/17/26 07:43, Philippe Mathieu-Daudé wrote:
> GDBFeature::num_regs holds the number of registers, but when using
> the compound literal construction, if the last array entry is not
> set, the array will be shorter. Prevent array overrun by making the
> array length explicit,
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   scripts/feature_to_c.py | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~

> 
> diff --git a/scripts/feature_to_c.py b/scripts/feature_to_c.py
> index 807af0e685c..3aa62fb895f 100644
> --- a/scripts/feature_to_c.py
> +++ b/scripts/feature_to_c.py
> @@ -90,13 +90,16 @@ def writeliteral(indent, bytes):
>       writeliteral(8, read)
>       sys.stdout.write(',\n')
>       writeliteral(8, bytes(feature_name, 'utf-8'))
> -    sys.stdout.write(',\n        (const char * const []) {\n')
> +    sys.stdout.write(',\n')
> +    sys.stdout.write(f'        (const char * const [{num_regs}]) {{\n')
>   
>       for index, regname in enumerate(regnames):
>           sys.stdout.write(f'            [{regnums[index] - base_reg}] =\n')
>           writeliteral(16, bytes(regname, 'utf-8'))
>           sys.stdout.write(',\n')
>   
> -    sys.stdout.write(f'        }},\n        {num_regs},\n    }},\n')
> +    sys.stdout.write( '        },\n')
> +    sys.stdout.write(f'        {num_regs},\n')
> +    sys.stdout.write( '    },\n')
>   
>   sys.stdout.write('    { NULL }\n};\n')