Move the declaration of variables to their scope of usage

Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
This commit is contained in:
Gabor Mezei 2022-08-12 15:40:09 +02:00
parent 7f93264ab1
commit 5a5c0c5f0a
No known key found for this signature in database
GPG key ID: F072ACA227ACD71D
2 changed files with 6 additions and 10 deletions

View file

@ -164,8 +164,7 @@ int mbedtls_mpi_core_read_le( mbedtls_mpi_uint *X,
const unsigned char *buf,
size_t buflen )
{
size_t i;
size_t const limbs = CHARS_TO_LIMBS( buflen );
const size_t limbs = CHARS_TO_LIMBS( buflen );
if( nx < limbs )
return( MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL );
@ -174,7 +173,7 @@ int mbedtls_mpi_core_read_le( mbedtls_mpi_uint *X,
{
memset( X, 0, nx * ciL );
for( i = 0; i < buflen; i++ )
for( size_t i = 0; i < buflen; i++ )
X[i / ciL] |= ((mbedtls_mpi_uint) buf[i]) << ((i % ciL) << 3);
}
@ -186,9 +185,7 @@ int mbedtls_mpi_core_read_be( mbedtls_mpi_uint *X,
const unsigned char *buf,
size_t buflen )
{
size_t const limbs = CHARS_TO_LIMBS( buflen );
size_t overhead;
unsigned char *Xp;
const size_t limbs = CHARS_TO_LIMBS( buflen );
if( nx < limbs )
return( MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL );
@ -197,13 +194,13 @@ int mbedtls_mpi_core_read_be( mbedtls_mpi_uint *X,
{
memset( X, 0, nx * ciL );
overhead = ( nx * ciL ) - buflen;
const size_t overhead = ( nx * ciL ) - buflen;
/* Avoid calling `memcpy` with NULL source or destination argument,
* even if buflen is 0. */
if( buf != NULL )
{
Xp = (unsigned char*) X;
unsigned char *Xp = (unsigned char *) X;
memcpy( Xp + overhead, buf, buflen );
mbedtls_mpi_core_bigendian_to_host( X, nx );

View file

@ -748,14 +748,13 @@ unsigned mbedtls_mpi_core_lt_ct( const mbedtls_mpi_uint *X,
const mbedtls_mpi_uint *Y,
size_t len )
{
size_t i;
unsigned ret, cond, done;
/* The value of any of these variables is either 0 or 1 for the rest of
* their scope. */
ret = cond = done = 0;
for( i = len; i > 0; i-- )
for( size_t i = len; i > 0; i-- )
{
/*
* If Y[i - 1] < X[i - 1] then X < Y is false and the result must