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/psa/crypto_examples.c b/programs/psa/crypto_examples.c
index 935d657..80fe67e 100644
--- a/programs/psa/crypto_examples.c
+++ b/programs/psa/crypto_examples.c
@@ -54,7 +54,7 @@
"and/or MBEDTLS_CIPHER_MODE_WITH_PADDING "
"not defined and/or MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER"
" defined.\r\n" );
- return( 0 );
+ return 0 ;
}
#else
@@ -91,7 +91,7 @@
*output_len += len;
exit:
- return( status );
+ return status ;
}
static psa_status_t cipher_encrypt( psa_key_id_t key,
@@ -122,7 +122,7 @@
exit:
psa_cipher_abort( &operation );
- return( status );
+ return status ;
}
static psa_status_t cipher_decrypt( psa_key_id_t key,
@@ -152,7 +152,7 @@
exit:
psa_cipher_abort( &operation );
- return( status );
+ return status ;
}
static psa_status_t
@@ -201,7 +201,7 @@
exit:
psa_destroy_key( key );
- return( status );
+ return status ;
}
static psa_status_t cipher_example_encrypt_decrypt_aes_cbc_pkcs7_multi( void )
@@ -249,7 +249,7 @@
exit:
psa_destroy_key( key );
- return( status );
+ return status ;
}
static psa_status_t cipher_example_encrypt_decrypt_aes_ctr_multi( void )
@@ -296,7 +296,7 @@
exit:
psa_destroy_key( key );
- return( status );
+ return status ;
}
static void cipher_examples( void )
@@ -325,7 +325,7 @@
cipher_examples( );
exit:
mbedtls_psa_crypto_free( );
- return( 0 );
+ return 0 ;
}
#endif /* MBEDTLS_PSA_CRYPTO_C && MBEDTLS_AES_C && MBEDTLS_CIPHER_MODE_CBC &&
MBEDTLS_CIPHER_MODE_CTR && MBEDTLS_CIPHER_MODE_WITH_PADDING */
diff --git a/programs/psa/key_ladder_demo.c b/programs/psa/key_ladder_demo.c
index cad875e..435c9ce 100644
--- a/programs/psa/key_ladder_demo.c
+++ b/programs/psa/key_ladder_demo.c
@@ -72,7 +72,7 @@
"MBEDTLS_PSA_CRYPTO_C and/or MBEDTLS_FS_IO "
"not defined and/or MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER "
"defined.\n" );
- return( 0 );
+ return 0 ;
}
#else
@@ -184,7 +184,7 @@
exit:
if( key_file != NULL)
fclose( key_file );
- return( status );
+ return status ;
}
/* Generate a master key for use in this demo.
@@ -210,7 +210,7 @@
exit:
(void) psa_destroy_key( key );
- return( status );
+ return status ;
}
/* Load the master key from a file.
@@ -259,7 +259,7 @@
(void) psa_destroy_key( *master_key );
*master_key = 0;
}
- return( status );
+ return status ;
}
/* Derive the intermediate keys, using the list of labels provided on
@@ -314,7 +314,7 @@
psa_destroy_key( *key );
*key = 0;
}
- return( status );
+ return status ;
}
/* Derive a wrapping key from the last intermediate key. */
@@ -351,7 +351,7 @@
exit:
psa_key_derivation_abort( &operation );
- return( status );
+ return status ;
}
static psa_status_t wrap_data( const char *input_file_name,
@@ -433,7 +433,7 @@
if( buffer != NULL )
mbedtls_platform_zeroize( buffer, buffer_size );
free( buffer );
- return( status );
+ return status ;
}
static psa_status_t unwrap_data( const char *input_file_name,
@@ -522,7 +522,7 @@
if( buffer != NULL )
mbedtls_platform_zeroize( buffer, ciphertext_size );
free( buffer );
- return( status );
+ return status ;
}
static psa_status_t run( enum program_mode mode,
@@ -540,7 +540,7 @@
/* Generate mode is unlike the others. Generate the master key and exit. */
if( mode == MODE_GENERATE )
- return( generate( key_file_name ) );
+ return generate( key_file_name ) ;
/* Read the master key. */
PSA_CHECK( import_key_from_file( PSA_KEY_USAGE_DERIVE | PSA_KEY_USAGE_EXPORT,
@@ -584,7 +584,7 @@
(void) psa_destroy_key( wrapping_key );
/* Deinitialize the PSA crypto library. */
mbedtls_psa_crypto_free( );
- return( status );
+ return status ;
}
static void usage( void )
@@ -625,7 +625,7 @@
strcmp( argv[1], "--help" ) == 0 )
{
usage( );
- return( EXIT_SUCCESS );
+ return EXIT_SUCCESS ;
}
for( i = 2; i < argc; i++ )
@@ -646,7 +646,7 @@
{
printf( "Maximum ladder depth %u exceeded.\n",
(unsigned) MAX_LADDER_DEPTH );
- return( EXIT_FAILURE );
+ return EXIT_FAILURE ;
}
ladder[ladder_depth] = q;
++ladder_depth;
@@ -680,13 +680,13 @@
( mode == MODE_WRAP || mode == MODE_UNWRAP ) )
{
printf( "Required argument missing: input\n" );
- return( DEMO_ERROR );
+ return DEMO_ERROR ;
}
if( output_file_name == NULL &&
( mode == MODE_SAVE || mode == MODE_WRAP || mode == MODE_UNWRAP ) )
{
printf( "Required argument missing: output\n" );
- return( DEMO_ERROR );
+ return DEMO_ERROR ;
}
status = run( mode, key_file_name,
@@ -698,6 +698,6 @@
usage_failure:
usage( );
- return( EXIT_FAILURE );
+ return EXIT_FAILURE ;
}
#endif /* MBEDTLS_SHA256_C && MBEDTLS_MD_C && MBEDTLS_AES_C && MBEDTLS_CCM_C && MBEDTLS_PSA_CRYPTO_C && MBEDTLS_FS_IO */
diff --git a/programs/psa/psa_constant_names.c b/programs/psa/psa_constant_names.c
index b5fea04..94edde5 100644
--- a/programs/psa/psa_constant_names.c
+++ b/programs/psa/psa_constant_names.c
@@ -33,7 +33,7 @@
/* Avoid calling the invalid parameter handler by checking ourselves */
if( s == NULL || n == 0 || fmt == NULL )
- return( -1 );
+ return -1 ;
va_start( argp, fmt );
#if defined(_TRUNCATE) && !defined(__MINGW32__)
@@ -48,7 +48,7 @@
#endif
va_end( argp );
- return( ret );
+ return ret ;
}
#endif