gdbstub: Make generated compound literal array size explicit
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: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> Message-Id: <20260216214332.47639-1-philmd@linaro.org>
Philippe Mathieu-Daudé committed
Feb 16, 2026 at 14:11 UTC
744bafc3f20b4b87141729af673f92118ac9a93c
1 file changed
+5
-2
scripts/feature_to_c.py
+5
-2
@@ -90,13 +90,16 @@ for input in sys.argv[1:]:
90
writeliteral(8, read)
91
sys.stdout.write(',\n')
92
writeliteral(8, bytes(feature_name, 'utf-8'))
93
- sys.stdout.write(',\n (const char * const []) {\n')
93
+ sys.stdout.write(',\n')
94
+ sys.stdout.write(f' (const char * const [{num_regs}]) {{\n')
95
96
for index, regname in enumerate(regnames):
97
sys.stdout.write(f' [{regnums[index] - base_reg}] =\n')
98
writeliteral(16, bytes(regname, 'utf-8'))
99
sys.stdout.write(',\n')
100
100
- sys.stdout.write(f' }},\n {num_regs},\n }},\n')
101
+ sys.stdout.write( ' },\n')
102
+ sys.stdout.write(f' {num_regs},\n')
103
+ sys.stdout.write( ' },\n')
104
105
sys.stdout.write(' { NULL }\n};\n')