Browse Source

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>
master
Philippe Mathieu-Daudé 6 months ago
parent
commit
744bafc3f2
  1. 7
      scripts/feature_to_c.py

7
scripts/feature_to_c.py

@ -90,13 +90,16 @@ for input in sys.argv[1:]:
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')

Loading…
Cancel
Save