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/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c
index 25fe21b..5477096 100644
--- a/programs/ssl/ssl_client2.c
+++ b/programs/ssl/ssl_client2.c
@@ -518,7 +518,7 @@
memcpy( peer_crt_info, buf, sizeof( buf ) );
if( opt.debug_level == 0 )
- return( 0 );
+ return 0 ;
mbedtls_printf( "%s", buf );
#else
@@ -534,7 +534,7 @@
mbedtls_printf( "%s\n", buf );
}
- return( 0 );
+ return 0 ;
}
#endif /* MBEDTLS_X509_CRT_PARSE_C */
@@ -548,7 +548,7 @@
int cid_negotiated;
if( opt.transport != MBEDTLS_SSL_TRANSPORT_DATAGRAM )
- return( 0 );
+ return 0 ;
/* Check if the use of a CID has been negotiated,
* but don't ask for the CID value and length.
@@ -566,7 +566,7 @@
{
mbedtls_printf( " failed\n ! mbedtls_ssl_get_peer_cid returned -0x%x\n\n",
(unsigned int) -ret );
- return( ret );
+ return ret ;
}
if( cid_negotiated == MBEDTLS_SSL_CID_DISABLED )
@@ -590,7 +590,7 @@
{
mbedtls_printf( " failed\n ! mbedtls_ssl_get_peer_cid returned -0x%x\n\n",
(unsigned int) -ret );
- return( ret );
+ return ret ;
}
/* Ask for just length + value of the peer's CID. */
@@ -600,7 +600,7 @@
{
mbedtls_printf( " failed\n ! mbedtls_ssl_get_peer_cid returned -0x%x\n\n",
(unsigned int) -ret );
- return( ret );
+ return ret ;
}
mbedtls_printf( "(%s) Peer CID (length %u Bytes): ",
additional_description,
@@ -613,7 +613,7 @@
mbedtls_printf( "\n" );
}
- return( 0 );
+ return 0 ;
}
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
diff --git a/programs/ssl/ssl_context_info.c b/programs/ssl/ssl_context_info.c
index 5ad9120..67e922c 100644
--- a/programs/ssl/ssl_context_info.c
+++ b/programs/ssl/ssl_context_info.c
@@ -30,7 +30,7 @@
{
printf("MBEDTLS_X509_CRT_PARSE_C and/or MBEDTLS_ERROR_C and/or "
"MBEDTLS_SSL_TLS_C not defined.\n");
- return( 0 );
+ return 0 ;
}
#else
diff --git a/programs/ssl/ssl_mail_client.c b/programs/ssl/ssl_mail_client.c
index 32960ad..2477979 100644
--- a/programs/ssl/ssl_mail_client.c
+++ b/programs/ssl/ssl_mail_client.c
@@ -190,7 +190,7 @@
mbedtls_strerror( ret, (char *) buf, 1024 );
#endif
mbedtls_printf( " failed\n ! mbedtls_ssl_handshake returned %d: %s\n\n", ret, buf );
- return( -1 );
+ return -1 ;
}
}
@@ -227,7 +227,7 @@
mbedtls_printf( "%s\n", buf );
#endif
- return( 0 );
+ return 0 ;
}
static int write_ssl_data( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len )
@@ -244,7 +244,7 @@
}
}
- return( 0 );
+ return 0 ;
}
static int write_ssl_and_get_response( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len )
diff --git a/programs/ssl/ssl_pthread_server.c b/programs/ssl/ssl_pthread_server.c
index a8db4d8..4517309 100644
--- a/programs/ssl/ssl_pthread_server.c
+++ b/programs/ssl/ssl_pthread_server.c
@@ -267,7 +267,7 @@
thread_info->thread_complete = 1;
- return( NULL );
+ return NULL ;
}
static int thread_create( mbedtls_net_context *client_fd )
@@ -292,7 +292,7 @@
}
if( i == MAX_NUM_THREADS )
- return( -1 );
+ return -1 ;
/*
* Fill thread-info for thread
@@ -304,10 +304,10 @@
if( ( ret = pthread_create( &threads[i].thread, NULL, handle_ssl_connection,
&threads[i].data ) ) != 0 )
{
- return( ret );
+ return ret ;
}
- return( 0 );
+ return 0 ;
}
int main( void )
diff --git a/programs/ssl/ssl_server2.c b/programs/ssl/ssl_server2.c
index d2aa48a..ea6706d 100644
--- a/programs/ssl/ssl_server2.c
+++ b/programs/ssl/ssl_server2.c
@@ -616,13 +616,13 @@
static int get_auth_mode( const char *s )
{
if( strcmp( s, "none" ) == 0 )
- return( MBEDTLS_SSL_VERIFY_NONE );
+ return MBEDTLS_SSL_VERIFY_NONE ;
if( strcmp( s, "optional" ) == 0 )
- return( MBEDTLS_SSL_VERIFY_OPTIONAL );
+ return MBEDTLS_SSL_VERIFY_OPTIONAL ;
if( strcmp( s, "required" ) == 0 )
- return( MBEDTLS_SSL_VERIFY_REQUIRED );
+ return MBEDTLS_SSL_VERIFY_REQUIRED ;
- return( -1 );
+ return -1 ;
}
/*
@@ -701,7 +701,7 @@
if( ( new = mbedtls_calloc( 1, sizeof( sni_entry ) ) ) == NULL )
{
sni_free( cur );
- return( NULL );
+ return NULL ;
}
GET_ITEM( new->name );
@@ -760,12 +760,12 @@
cur = new;
}
- return( cur );
+ return cur ;
error:
sni_free( new );
sni_free( cur );
- return( NULL );
+ return NULL ;
}
/*
@@ -787,13 +787,13 @@
if( cur->authmode != DFL_AUTH_MODE )
mbedtls_ssl_set_hs_authmode( ssl, cur->authmode );
- return( mbedtls_ssl_set_hs_own_cert( ssl, cur->cert, cur->key ) );
+ return mbedtls_ssl_set_hs_own_cert( ssl, cur->cert, cur->key ) ;
}
cur = cur->next;
}
- return( -1 );
+ return -1 ;
}
#endif /* SNI_OPTION */
@@ -830,7 +830,7 @@
{
status = psa_destroy_key( slot );
if( status != PSA_SUCCESS )
- return( status );
+ return status ;
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */
@@ -839,7 +839,7 @@
head = next;
}
- return( 0 );
+ return 0 ;
}
/*
@@ -877,12 +877,12 @@
cur = new;
}
- return( cur );
+ return cur ;
error:
psk_free( new );
psk_free( cur );
- return( 0 );
+ return 0 ;
}
/*
@@ -900,16 +900,16 @@
{
#if defined(MBEDTLS_USE_PSA_CRYPTO)
if( cur->slot != 0 )
- return( mbedtls_ssl_set_hs_psk_opaque( ssl, cur->slot ) );
+ return mbedtls_ssl_set_hs_psk_opaque( ssl, cur->slot ) ;
else
#endif
- return( mbedtls_ssl_set_hs_psk( ssl, cur->key, cur->key_len ) );
+ return mbedtls_ssl_set_hs_psk( ssl, cur->key, cur->key_len ) ;
}
cur = cur->next;
}
- return( -1 );
+ return -1 ;
}
#endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */
@@ -977,13 +977,13 @@
unsigned delay )
{
if( ctx->slots_used >= sizeof( ctx->slots ) / sizeof( *ctx->slots ) )
- return( -1 );
+ return -1 ;
ctx->slots[ctx->slots_used].cert = cert;
ctx->slots[ctx->slots_used].pk = pk;
ctx->slots[ctx->slots_used].delay = delay;
ctx->slots[ctx->slots_used].pk_owned = pk_take_ownership;
++ctx->slots_used;
- return( 0 );
+ return 0 ;
}
#define SSL_ASYNC_INPUT_MAX_SIZE 512
@@ -1047,7 +1047,7 @@
{
mbedtls_printf( "Async %s callback: no key matches this certificate.\n",
op_name );
- return( MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH );
+ return MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH ;
}
mbedtls_printf( "Async %s callback: using key slot %u, delay=%u.\n",
op_name, slot, config_data->slots[slot].delay );
@@ -1055,15 +1055,15 @@
if( config_data->inject_error == SSL_ASYNC_INJECT_ERROR_START )
{
mbedtls_printf( "Async %s callback: injected error\n", op_name );
- return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE );
+ return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ;
}
if( input_len > SSL_ASYNC_INPUT_MAX_SIZE )
- return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
+ return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ;
ctx = mbedtls_calloc( 1, sizeof( *ctx ) );
if( ctx == NULL )
- return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
+ return MBEDTLS_ERR_SSL_ALLOC_FAILED ;
ctx->slot = slot;
ctx->operation_type = op_type;
ctx->md_alg = md_alg;
@@ -1073,9 +1073,9 @@
mbedtls_ssl_set_async_operation_data( ssl, ctx );
if( ctx->remaining_delay == 0 )
- return( 0 );
+ return 0 ;
else
- return( MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS );
+ return MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS ;
}
static int ssl_async_sign( mbedtls_ssl_context *ssl,
@@ -1116,7 +1116,7 @@
--ctx->remaining_delay;
mbedtls_printf( "Async resume (slot %u): call %u more times.\n",
ctx->slot, ctx->remaining_delay );
- return( MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS );
+ return MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS ;
}
switch( ctx->operation_type )
@@ -1138,7 +1138,7 @@
mbedtls_printf( "Async resume (slot %u): unknown operation type %ld. This shouldn't happen.\n",
ctx->slot, (long) ctx->operation_type );
mbedtls_free( ctx );
- return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE );
+ return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ;
break;
}
@@ -1149,13 +1149,13 @@
mbedtls_printf( "Async resume callback: %s done but injected error\n",
op_name );
mbedtls_free( ctx );
- return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE );
+ return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ;
}
mbedtls_printf( "Async resume (slot %u): %s done, status=%d.\n",
ctx->slot, op_name, ret );
mbedtls_free( ctx );
- return( ret );
+ return ret ;
}
static void ssl_async_cancel( mbedtls_ssl_context *ssl )
@@ -1184,10 +1184,10 @@
if( status != PSA_SUCCESS )
{
fprintf( stderr, "IMPORT\n" );
- return( status );
+ return status ;
}
- return( PSA_SUCCESS );
+ return PSA_SUCCESS ;
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */
@@ -1201,7 +1201,7 @@
int cid_negotiated;
if( opt.transport != MBEDTLS_SSL_TRANSPORT_DATAGRAM )
- return( 0 );
+ return 0 ;
/* Check if the use of a CID has been negotiated */
ret = mbedtls_ssl_get_peer_cid( ssl, &cid_negotiated,
@@ -1210,7 +1210,7 @@
{
mbedtls_printf( " failed\n ! mbedtls_ssl_get_peer_cid returned -0x%x\n\n",
(unsigned int) -ret );
- return( ret );
+ return ret ;
}
if( cid_negotiated == MBEDTLS_SSL_CID_DISABLED )
@@ -1237,7 +1237,7 @@
mbedtls_printf( "\n" );
}
- return( 0 );
+ return 0 ;
}
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
diff --git a/programs/ssl/ssl_test_common_source.c b/programs/ssl/ssl_test_common_source.c
index 6ec4171..6ca7af3 100644
--- a/programs/ssl/ssl_test_common_source.c
+++ b/programs/ssl/ssl_test_common_source.c
@@ -152,7 +152,7 @@
* so make a copy. */
tmp_buf = mbedtls_calloc( 1, len );
if( tmp_buf == NULL )
- return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
+ return MBEDTLS_ERR_SSL_ALLOC_FAILED ;
memcpy( tmp_buf, buf, len );
ret_cr1 = mbedtls_ssl_check_record( ssl, tmp_buf, len );
@@ -201,7 +201,7 @@
cleanup:
mbedtls_free( tmp_buf );
- return( my_ret );
+ return my_ret ;
}
int recv_cb( void *ctx, unsigned char *buf, size_t len )
@@ -215,7 +215,7 @@
else
ret = mbedtls_net_recv( io_ctx->net, buf, len );
if( ret < 0 )
- return( ret );
+ return ret ;
recv_len = (size_t) ret;
if( opt.transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
@@ -224,10 +224,10 @@
* in between receiving the packet from the underlying
* transport and passing it on to the TLS stack. */
if( ssl_check_record( io_ctx->ssl, buf, recv_len ) != 0 )
- return( -1 );
+ return -1 ;
}
- return( (int) recv_len );
+ return (int) recv_len ;
}
int recv_timeout_cb( void *ctx, unsigned char *buf, size_t len,
@@ -239,7 +239,7 @@
ret = mbedtls_net_recv_timeout( io_ctx->net, buf, len, timeout );
if( ret < 0 )
- return( ret );
+ return ret ;
recv_len = (size_t) ret;
if( opt.transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
@@ -248,10 +248,10 @@
* in between receiving the packet from the underlying
* transport and passing it on to the TLS stack. */
if( ssl_check_record( io_ctx->ssl, buf, recv_len ) != 0 )
- return( -1 );
+ return -1 ;
}
- return( (int) recv_len );
+ return (int) recv_len ;
}
int send_cb( void *ctx, unsigned char const *buf, size_t len )
@@ -259,9 +259,9 @@
io_ctx_t *io_ctx = (io_ctx_t*) ctx;
if( opt.nbio == 2 )
- return( delayed_send( io_ctx->net, buf, len ) );
+ return delayed_send( io_ctx->net, buf, len ) ;
- return( mbedtls_net_send( io_ctx->net, buf, len ) );
+ return mbedtls_net_send( io_ctx->net, buf, len ) ;
}
#if defined(MBEDTLS_X509_CRT_PARSE_C)
@@ -294,7 +294,7 @@
uint32_t flags )
{
#if !defined(MBEDTLS_X509_REMOVE_INFO)
- return( mbedtls_x509_crt_verify_info( buf, size, prefix, flags ) );
+ return mbedtls_x509_crt_verify_info( buf, size, prefix, flags ) ;
#else /* !MBEDTLS_X509_REMOVE_INFO */
int ret;
diff --git a/programs/ssl/ssl_test_lib.c b/programs/ssl/ssl_test_lib.c
index 04e127a..382682f 100644
--- a/programs/ssl/ssl_test_lib.c
+++ b/programs/ssl/ssl_test_lib.c
@@ -65,7 +65,7 @@
//replace result with pseudo random
output[i] = (unsigned char) rand();
}
- return( ret );
+ return ret ;
}
#endif
@@ -95,7 +95,7 @@
{
mbedtls_fprintf( stderr,
"MBEDTLS_USE_PSA_CRYPTO does not support reproducible mode.\n" );
- return( -1 );
+ return -1 ;
}
#endif
#if defined(MBEDTLS_TEST_USE_PSA_CRYPTO_RNG)
@@ -106,9 +106,9 @@
{
mbedtls_fprintf( stderr,
"The PSA RNG does not support reproducible mode.\n" );
- return( -1 );
+ return -1 ;
}
- return( 0 );
+ return 0 ;
#else /* !MBEDTLS_TEST_USE_PSA_CRYPTO_RNG */
int ( *f_entropy )( void *, unsigned char *, size_t ) =
( reproducible ? dummy_entropy : mbedtls_entropy_func );
@@ -142,11 +142,11 @@
{
mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned -0x%x\n",
(unsigned int) -ret );
- return( ret );
+ return ret ;
}
#endif /* !MBEDTLS_TEST_USE_PSA_CRYPTO_RNG */
- return( 0 );
+ return 0 ;
}
void rng_free( rng_context_t *rng )
@@ -181,9 +181,9 @@
rng_context_t *rng = p_rng;
#if defined(MBEDTLS_CTR_DRBG_C)
- return( mbedtls_ctr_drbg_random( &rng->drbg, output, output_len ) );
+ return mbedtls_ctr_drbg_random( &rng->drbg, output, output_len ) ;
#elif defined(MBEDTLS_HMAC_DRBG_C)
- return( mbedtls_hmac_drbg_random( &rng->drbg, output, output_len ) );
+ return mbedtls_hmac_drbg_random( &rng->drbg, output, output_len ) ;
#else
#error "No DRBG available"
#endif
@@ -243,7 +243,7 @@
}
*candidates = first;
- return( ret );
+ return ret ;
}
#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
@@ -255,13 +255,13 @@
if( first_try )
{
first_try = 0;
- return( MBEDTLS_ERR_SSL_WANT_READ );
+ return MBEDTLS_ERR_SSL_WANT_READ ;
}
ret = mbedtls_net_recv( ctx, buf, len );
if( ret != MBEDTLS_ERR_SSL_WANT_READ )
first_try = 1; /* Next call will be a new operation */
- return( ret );
+ return ret ;
}
int delayed_send( void *ctx, const unsigned char *buf, size_t len )
@@ -272,13 +272,13 @@
if( first_try )
{
first_try = 0;
- return( MBEDTLS_ERR_SSL_WANT_WRITE );
+ return MBEDTLS_ERR_SSL_WANT_WRITE ;
}
ret = mbedtls_net_send( ctx, buf, len );
if( ret != MBEDTLS_ERR_SSL_WANT_WRITE )
first_try = 1; /* Next call will be a new operation */
- return( ret );
+ return ret ;
}
#if !defined(MBEDTLS_TIMING_C)
@@ -299,7 +299,7 @@
poll_type = MBEDTLS_NET_POLL_READ;
#if !defined(MBEDTLS_TIMING_C)
else
- return( 0 );
+ return 0 ;
#endif
while( 1 )
@@ -318,13 +318,13 @@
{
ret = mbedtls_net_poll( fd, poll_type, 0 );
if( ret < 0 )
- return( ret );
+ return ret ;
if( ret == poll_type )
break;
}
}
- return( 0 );
+ return 0 ;
}
#if defined(MBEDTLS_TEST_HOOKS)
@@ -346,8 +346,8 @@
#endif
if( mbedtls_test_info.result != MBEDTLS_TEST_RESULT_SUCCESS )
- return( 1 );
- return( 0 );
+ return 1 ;
+ return 0 ;
}
void test_hooks_free( void )