Skip to content

Commit c4cd2ad

Browse files
test_psa_constant_names: fix uses of C integer types
Some of the types may in principle be wider than `unsigned`, so use `unsigned long` in printf. Add support for signed types: a status is a signed value, and preferentially printed in decimal.
1 parent 3f77526 commit c4cd2ad

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tests/scripts/test_psa_constant_names.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ def remove_file_if_exists(filename):
211211

212212
def run_c(options, type, names):
213213
'''Generate and run a program to print out numerical values for names.'''
214+
if type == 'status':
215+
cast_to = 'long'
216+
printf_format = '%ld'
217+
else:
218+
cast_to = 'unsigned long'
219+
printf_format = '0x%08lx'
214220
c_name = None
215221
exe_name = None
216222
try:
@@ -230,7 +236,8 @@ def run_c(options, type, names):
230236
{
231237
''')
232238
for name in names:
233-
c_file.write(' printf("0x%08x\\n", {});\n'.format(name))
239+
c_file.write(' printf("{}\\n", ({}) {});\n'
240+
.format(printf_format, cast_to, name))
234241
c_file.write(''' return 0;
235242
}
236243
''')

0 commit comments

Comments
 (0)