Skip to content

Commit 0a08d33

Browse files
committed
Fix warnings from clang-16
Running clang-16 on mbedtls reports warnings of type "-Wstrict-prototypes". This patch fixes these warnings by adding void to functions with no arguments. The generate_test_code.py is modified to insert void into test functions with no arguments in*.function files. Signed-off-by: Gowtham Suresh Kumar <[email protected]>
1 parent c12fc7d commit 0a08d33

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

library/ecp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3639,7 +3639,7 @@ int mbedtls_ecp_self_test(int verbose)
36393639
#if defined(MBEDTLS_TEST_HOOKS)
36403640

36413641
MBEDTLS_STATIC_TESTABLE
3642-
mbedtls_ecp_variant mbedtls_ecp_get_variant()
3642+
mbedtls_ecp_variant mbedtls_ecp_get_variant(void)
36433643
{
36443644
return MBEDTLS_ECP_VARIANT_WITH_MPI_STRUCT;
36453645
}

tests/scripts/generate_test_code.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,11 @@ def parse_function_code(funcs_f, dependencies, suite_dependencies):
667667
code = code.replace(name, 'test_' + name, 1)
668668
name = 'test_' + name
669669

670+
# If a test function has no arguments then add 'void' argument to
671+
# avoid "-Wstrict-prototypes" warnings from clang-16
672+
if len(args) == 0:
673+
code = code.replace('()', '(void)', 1)
674+
670675
for line in funcs_f:
671676
if re.search(END_CASE_REGEX, line):
672677
break

tests/scripts/test_generate_test_code.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ def test_return(self, parse_function_arguments_mock,
647647
self.assertEqual(arg, [])
648648
expected = '''#line 1 "test_suite_ut.function"
649649
650-
void test_func()
650+
void test_func(void)
651651
{
652652
ba ba black sheep
653653
have you any wool
@@ -690,7 +690,7 @@ def test_with_exit_label(self, parse_function_arguments_mock,
690690

691691
expected = '''#line 1 "test_suite_ut.function"
692692
693-
void test_func()
693+
void test_func(void)
694694
{
695695
ba ba black sheep
696696
have you any wool
@@ -750,7 +750,7 @@ def test_function_name_on_newline(self, parse_function_arguments_mock,
750750
void
751751
752752
753-
test_func()
753+
test_func(void)
754754
{
755755
ba ba black sheep
756756
have you any wool
@@ -803,7 +803,7 @@ def test_case_starting_with_comment(self, parse_function_arguments_mock,
803803
804804
805805
806-
void test_func()
806+
void test_func(void)
807807
{
808808
ba ba black sheep
809809
have you any wool
@@ -1139,7 +1139,7 @@ def test_parsing(self):
11391139
#if defined(MBEDTLS_ENTROPY_NV_SEED)
11401140
#if defined(MBEDTLS_FS_IO)
11411141
#line 13 "test_suite_ut.function"
1142-
void test_func1()
1142+
void test_func1(void)
11431143
{
11441144
exit:
11451145
;
@@ -1156,7 +1156,7 @@ def test_parsing(self):
11561156
#if defined(MBEDTLS_ENTROPY_NV_SEED)
11571157
#if defined(MBEDTLS_FS_IO)
11581158
#line 19 "test_suite_ut.function"
1159-
void test_func2()
1159+
void test_func2(void)
11601160
{
11611161
exit:
11621162
;
@@ -1171,7 +1171,7 @@ def test_parsing(self):
11711171
#endif /* MBEDTLS_FS_IO */
11721172
#endif /* MBEDTLS_ENTROPY_NV_SEED */
11731173
#endif /* MBEDTLS_ECP_C */
1174-
'''
1174+
'''
11751175
self.assertEqual(func_code, expected_func_code)
11761176
self.assertEqual(func_info, {'test_func1': (0, []),
11771177
'test_func2': (1, [])})

0 commit comments

Comments
 (0)