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/pkey/ecdh_curve25519.c b/programs/pkey/ecdh_curve25519.c
index ca046fd..fcef380 100644
--- a/programs/pkey/ecdh_curve25519.c
+++ b/programs/pkey/ecdh_curve25519.c
@@ -73,7 +73,7 @@
mbedtls_entropy_init( &entropy );
if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy,
(const unsigned char *) pers,
- sizeof pers ) ) != 0 )
+ sizeof(pers) ) ) != 0 )
{
mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret );
goto exit;
diff --git a/programs/pkey/ecdsa.c b/programs/pkey/ecdsa.c
index 6b6e951..293bfba 100644
--- a/programs/pkey/ecdsa.c
+++ b/programs/pkey/ecdsa.c
@@ -81,7 +81,7 @@
size_t len;
if( mbedtls_ecp_point_write_binary( &key->MBEDTLS_PRIVATE(grp), &key->MBEDTLS_PRIVATE(Q),
- MBEDTLS_ECP_PF_UNCOMPRESSED, &len, buf, sizeof buf ) != 0 )
+ MBEDTLS_ECP_PF_UNCOMPRESSED, &len, buf, sizeof(buf) ) != 0 )
{
mbedtls_printf("internal error\n");
return;
diff --git a/programs/pkey/gen_key.c b/programs/pkey/gen_key.c
index 4043dfa..8729be3 100644
--- a/programs/pkey/gen_key.c
+++ b/programs/pkey/gen_key.c
@@ -61,7 +61,7 @@
file = fopen( "/dev/random", "rb" );
if( file == NULL )
- return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
+ return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ;
while( left > 0 )
{
@@ -70,7 +70,7 @@
if( ret == 0 && ferror( file ) )
{
fclose( file );
- return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
+ return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ;
}
p += ret;
@@ -80,7 +80,7 @@
fclose( file );
*olen = len;
- return( 0 );
+ return 0 ;
}
#endif /* !_WIN32 */
#endif
@@ -157,31 +157,31 @@
if( opt.format == FORMAT_PEM )
{
if( ( ret = mbedtls_pk_write_key_pem( key, output_buf, 16000 ) ) != 0 )
- return( ret );
+ return ret ;
len = strlen( (char *) output_buf );
}
else
{
if( ( ret = mbedtls_pk_write_key_der( key, output_buf, 16000 ) ) < 0 )
- return( ret );
+ return ret ;
len = ret;
c = output_buf + sizeof(output_buf) - len;
}
if( ( f = fopen( output_file, "wb" ) ) == NULL )
- return( -1 );
+ return -1 ;
if( fwrite( c, 1, len, f ) != len )
{
fclose( f );
- return( -1 );
+ return -1 ;
}
fclose( f );
- return( 0 );
+ return 0 ;
}
int main( int argc, char *argv[] )
diff --git a/programs/pkey/key_app_writer.c b/programs/pkey/key_app_writer.c
index 8a09af5..a61cda1 100644
--- a/programs/pkey/key_app_writer.c
+++ b/programs/pkey/key_app_writer.c
@@ -128,7 +128,7 @@
if( opt.output_format == OUTPUT_FORMAT_PEM )
{
if( ( ret = mbedtls_pk_write_pubkey_pem( key, output_buf, 16000 ) ) != 0 )
- return( ret );
+ return ret ;
len = strlen( (char *) output_buf );
}
@@ -136,24 +136,24 @@
#endif
{
if( ( ret = mbedtls_pk_write_pubkey_der( key, output_buf, 16000 ) ) < 0 )
- return( ret );
+ return ret ;
len = ret;
c = output_buf + sizeof(output_buf) - len;
}
if( ( f = fopen( output_file, "w" ) ) == NULL )
- return( -1 );
+ return -1 ;
if( fwrite( c, 1, len, f ) != len )
{
fclose( f );
- return( -1 );
+ return -1 ;
}
fclose( f );
- return( 0 );
+ return 0 ;
}
static int write_private_key( mbedtls_pk_context *key, const char *output_file )
@@ -170,7 +170,7 @@
if( opt.output_format == OUTPUT_FORMAT_PEM )
{
if( ( ret = mbedtls_pk_write_key_pem( key, output_buf, 16000 ) ) != 0 )
- return( ret );
+ return ret ;
len = strlen( (char *) output_buf );
}
@@ -178,24 +178,24 @@
#endif
{
if( ( ret = mbedtls_pk_write_key_der( key, output_buf, 16000 ) ) < 0 )
- return( ret );
+ return ret ;
len = ret;
c = output_buf + sizeof(output_buf) - len;
}
if( ( f = fopen( output_file, "w" ) ) == NULL )
- return( -1 );
+ return -1 ;
if( fwrite( c, 1, len, f ) != len )
{
fclose( f );
- return( -1 );
+ return -1 ;
}
fclose( f );
- return( 0 );
+ return 0 ;
}
int main( int argc, char *argv[] )