Fix parantheses on return and sizeof statements.
Used script:
```
import re
import sys
for arg in sys.argv[1:]:
print(arg)
with open(arg, 'r') as file:
content = file.read()
content = re.sub(r"return\s?\((?!.*\).*\()\s*\n?(.*)\n?\);", r"return \1;", \
content, flags = re.M)
content = re.sub(r"sizeof ([^\(][a-zA-Z0-9_\[\]]*)", r"sizeof(\1)",\
content, flags = re.M)
with open(arg, 'w') as file:
file.write(content)
```
Executed with:
` find . -regextype posix-egrep -regex ".*\.([hc]|fmt|function)" | xargs -L1 python script.py`
Signed-off-by: Mateusz Starzyk <mateusz.starzyk@mobica.com>
diff --git a/tests/suites/test_suite_x509parse.function b/tests/suites/test_suite_x509parse.function
index fea02f3..912364c 100644
--- a/tests/suites/test_suite_x509parse.function
+++ b/tests/suites/test_suite_x509parse.function
@@ -139,7 +139,7 @@
}
*candidates = first;
- return( ret );
+ return ret ;
}
#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
@@ -154,10 +154,10 @@
if( *levels & ( 1 << certificate_depth ) )
{
*flags |= ( 1 << certificate_depth );
- return( -1 - certificate_depth );
+ return -1 - certificate_depth ;
}
- return( 0 );
+ return 0 ;
}
/* strsep() not available on Windows */
@@ -167,7 +167,7 @@
char *ret = *stringp;
if( *stringp == NULL )
- return( NULL );
+ return NULL ;
for( ; ; (*stringp)++ )
{
@@ -187,7 +187,7 @@
}
done:
- return( ret );
+ return ret ;
}
#if defined(MBEDTLS_X509_CRT_PARSE_C)
@@ -227,7 +227,7 @@
ctx->p = p;
- return( 0 );
+ return 0 ;
}
int verify_parse_san( mbedtls_x509_subject_alternative_name *san,
@@ -265,7 +265,7 @@
if( san->san.other_name.value.hardware_module_name.val.len >= n )
{
*p = '\0';
- return( MBEDTLS_ERR_X509_BUFFER_TOO_SMALL );
+ return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL ;
}
for( i=0; i < san->san.other_name.value.hardware_module_name.val.len; i++ )
@@ -281,7 +281,7 @@
if( san->san.unstructured_name.len >= n )
{
*p = '\0';
- return( MBEDTLS_ERR_X509_BUFFER_TOO_SMALL );
+ return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL ;
}
n -= san->san.unstructured_name.len;
for( i = 0; i < san->san.unstructured_name.len; i++ )
@@ -292,7 +292,7 @@
/*
* Should not happen.
*/
- return( -1 );
+ return -1 ;
}
ret = mbedtls_snprintf( p, n, "\n" );
MBEDTLS_X509_SAFE_SNPRINTF;
@@ -300,7 +300,7 @@
*size = n;
*buf = p;
- return( 0 );
+ return 0 ;
}
int parse_crt_ext_cb( void *p_ctx, mbedtls_x509_crt const *crt, mbedtls_x509_buf const *oid,
@@ -321,7 +321,7 @@
ret = mbedtls_asn1_get_tag( p, end, &len,
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE );
if( ret != 0 )
- return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
+ return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ;
if( *p + len != end )
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
@@ -343,13 +343,13 @@
*/
if( ( ret = mbedtls_asn1_get_tag( p, end, &len,
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
- return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
+ return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ;
policy_end = *p + len;
if( ( ret = mbedtls_asn1_get_tag( p, policy_end, &len,
MBEDTLS_ASN1_OID ) ) != 0 )
- return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
+ return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ;
/*
* Recognize exclusively the policy with OID 1
@@ -367,7 +367,7 @@
{
if( ( ret = mbedtls_asn1_get_tag( p, policy_end, &len,
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
- return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
+ return MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) ;
/*
* Skip the optional policy qualifiers.
*/
@@ -383,11 +383,11 @@
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
- return( parse_ret );
+ return parse_ret ;
}
else if( new_oid != NULL && new_oid->tag == oid->tag && new_oid->len == oid->len &&
memcmp( new_oid->p, oid->p, oid->len ) == 0 )
- return( 0 );
+ return 0 ;
else
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) );
@@ -1059,9 +1059,9 @@
/* Load a chain with nb_int intermediates (from 01 to nb_int),
* plus one "end-entity" cert (nb_int + 1) */
- ret = mbedtls_snprintf( file_buf, sizeof file_buf, "%s/c%02d.pem", chain_dir,
+ ret = mbedtls_snprintf( file_buf, sizeof(file_buf), "%s/c%02d.pem", chain_dir,
nb_int + 1 );
- TEST_ASSERT( ret > 0 && (size_t) ret < sizeof file_buf );
+ TEST_ASSERT( ret > 0 && (size_t) ret < sizeof(file_buf) );
TEST_ASSERT( mbedtls_x509_crt_parse_file( &chain, file_buf ) == 0 );
/* Try to verify that chain */
@@ -1155,13 +1155,13 @@
mbedtls_x509_buf oid;
char num_buf[100];
- memset( num_buf, 0x2a, sizeof num_buf );
+ memset( num_buf, 0x2a, sizeof(num_buf) );
oid.tag = MBEDTLS_ASN1_OID;
oid.p = oid_buf->x;
oid.len = oid_buf->len;
- TEST_ASSERT( (size_t) blen <= sizeof num_buf );
+ TEST_ASSERT( (size_t) blen <= sizeof(num_buf) );
TEST_ASSERT( mbedtls_oid_get_numeric_string( num_buf, blen, &oid ) == ret );