mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-22 11:45:42 +01:00
Address review comments
- Use switch case instead of loop to generate faster code - Add #if defined to address compiler error Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
This commit is contained in:
parent
a9f64006ea
commit
a4a2aa5169
1254
library/error.c
1254
library/error.c
File diff suppressed because it is too large
Load Diff
@ -42,38 +42,16 @@
|
||||
|
||||
HEADER_INCLUDED
|
||||
|
||||
typedef struct mbedtls_error
|
||||
{
|
||||
int code; /* Error code. */
|
||||
const char * description; /* Error description. */
|
||||
} mbedtls_error_t;
|
||||
|
||||
static mbedtls_error_t high_level_errors[] =
|
||||
{
|
||||
HIGH_LEVEL_CODE_CHECKS
|
||||
};
|
||||
|
||||
#define NUM_HIGH_LEVEL_ERRORS ( sizeof(high_level_errors)/sizeof(mbedtls_error_t) )
|
||||
|
||||
static mbedtls_error_t low_level_errors[] =
|
||||
{
|
||||
LOW_LEVEL_CODE_CHECKS
|
||||
};
|
||||
|
||||
#define NUM_LOW_LEVEL_ERRORS ( sizeof(low_level_errors)/sizeof(mbedtls_error_t) )
|
||||
|
||||
const char * mbedtls_high_level_strerr( int error_code )
|
||||
{
|
||||
size_t i;
|
||||
const char *error_description = NULL;
|
||||
|
||||
for(i = 0; i < NUM_HIGH_LEVEL_ERRORS; i++ )
|
||||
switch( error_code )
|
||||
{
|
||||
if( high_level_errors[i].code == error_code )
|
||||
{
|
||||
error_description = high_level_errors[i].description;
|
||||
HIGH_LEVEL_CODE_CHECKS
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return error_description;
|
||||
@ -81,16 +59,14 @@ const char * mbedtls_high_level_strerr( int error_code )
|
||||
|
||||
const char * mbedtls_low_level_strerr( int error_code )
|
||||
{
|
||||
size_t i;
|
||||
const char *error_description = NULL;
|
||||
|
||||
for(i = 0; i < NUM_LOW_LEVEL_ERRORS; i++ )
|
||||
switch( error_code )
|
||||
{
|
||||
if( low_level_errors[i].code == error_code )
|
||||
{
|
||||
error_description = low_level_errors[i].description;
|
||||
LOW_LEVEL_CODE_CHECKS
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return error_description;
|
||||
@ -123,10 +99,12 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen )
|
||||
else
|
||||
mbedtls_snprintf( buf, buflen, "%s", high_level_error_description );
|
||||
|
||||
#if defined(MBEDTLS_SSL_TLS_C)
|
||||
// Early return in case of a fatal error - do not try to translate low
|
||||
// level code.
|
||||
if(use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE))
|
||||
return;
|
||||
#endif /* MBEDTLS_SSL_TLS_C */
|
||||
}
|
||||
|
||||
use_ret = ret & ~0xFF80;
|
||||
|
@ -119,13 +119,13 @@ foreach my $line (@matches)
|
||||
{
|
||||
$code_check = \$ll_code_check;
|
||||
$old_define = \$ll_old_define;
|
||||
$white_space = ' ';
|
||||
$white_space = ' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
$code_check = \$hl_code_check;
|
||||
$old_define = \$hl_old_define;
|
||||
$white_space = ' ';
|
||||
$white_space = ' ';
|
||||
}
|
||||
|
||||
if ($define_name ne ${$old_define})
|
||||
@ -160,7 +160,9 @@ foreach my $line (@matches)
|
||||
${$old_define} = $define_name;
|
||||
}
|
||||
|
||||
${$code_check} .= "${white_space}\{.code = -($error_name), .description=\"$module_name - $description\"},\n";
|
||||
${$code_check} .= "${white_space}case -($error_name):\n".
|
||||
"${white_space} error_description = \"$module_name - $description\";\n".
|
||||
"${white_space} break;\n"
|
||||
};
|
||||
|
||||
if ($ll_old_define ne "")
|
||||
|
Loading…
Reference in New Issue
Block a user