Static code analysis warning fixes

This commit is contained in:
libretroadmin 2025-07-18 09:26:26 +02:00
parent 180b39cd3d
commit cd0f159238
15 changed files with 101 additions and 103 deletions

View File

@ -1262,31 +1262,35 @@ void core_option_manager_free(core_option_manager_t *opt)
for (i = 0; i < opt->size; i++)
{
if (opt->opts[i].desc)
free(opt->opts[i].desc);
if (opt->opts[i].desc_categorized)
free(opt->opts[i].desc_categorized);
if (opt->opts[i].info)
free(opt->opts[i].info);
if (opt->opts[i].info_categorized)
free(opt->opts[i].info_categorized);
if (opt->opts[i].key)
free(opt->opts[i].key);
if (opt->opts[i].category_key)
free(opt->opts[i].category_key);
struct core_option *option = (struct core_option*)&opt->opts[i];
if (option)
{
if (option->desc)
free(option->desc);
if (option->desc_categorized)
free(option->desc_categorized);
if (option->info)
free(option->info);
if (option->info_categorized)
free(option->info_categorized);
if (option->key)
free(option->key);
if (option->category_key)
free(option->category_key);
if (opt->opts[i].vals)
string_list_free(opt->opts[i].vals);
if (opt->opts[i].val_labels)
string_list_free(opt->opts[i].val_labels);
if (option->vals)
string_list_free(option->vals);
if (option->val_labels)
string_list_free(option->val_labels);
opt->opts[i].desc = NULL;
opt->opts[i].desc_categorized = NULL;
opt->opts[i].info = NULL;
opt->opts[i].info_categorized = NULL;
opt->opts[i].key = NULL;
opt->opts[i].category_key = NULL;
opt->opts[i].vals = NULL;
option->desc = NULL;
option->desc_categorized = NULL;
option->info = NULL;
option->info_categorized = NULL;
option->key = NULL;
option->category_key = NULL;
option->vals = NULL;
}
}
if (opt->option_map)
@ -1318,11 +1322,11 @@ void core_option_manager_free(core_option_manager_t *opt)
* specified option category if successful,
* otherwise NULL.
**/
const char *core_option_manager_get_category_desc(core_option_manager_t *opt,
const char *key)
const char *core_option_manager_get_category_desc(
core_option_manager_t *opt, const char *key)
{
uint32_t key_hash;
size_t i;
uint32_t key_hash;
if ( !opt
|| string_is_empty(key))
@ -1360,11 +1364,11 @@ const char *core_option_manager_get_category_desc(core_option_manager_t *opt,
const char *core_option_manager_get_category_info(core_option_manager_t *opt,
const char *key)
{
uint32_t key_hash;
size_t i;
uint32_t key_hash;
if (!opt ||
string_is_empty(key))
if ( !opt
|| string_is_empty(key))
return NULL;
key_hash = core_option_manager_hash_string(key);

View File

@ -306,7 +306,7 @@ static int pk_group_from_specified( const mbedtls_asn1_buf *params, mbedtls_ecp_
p += len;
/* Ignore seed BIT STRING OPTIONAL */
if( ( ret = mbedtls_asn1_get_tag( &p, end_curve, &len, MBEDTLS_ASN1_BIT_STRING ) ) == 0 )
if( (mbedtls_asn1_get_tag( &p, end_curve, &len, MBEDTLS_ASN1_BIT_STRING)) == 0 )
p += len;
if( p != end_curve )
@ -316,25 +316,23 @@ static int pk_group_from_specified( const mbedtls_asn1_buf *params, mbedtls_ecp_
/*
* ECPoint ::= OCTET STRING
*/
if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 )
if ((ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 )
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
if( ( ret = mbedtls_ecp_point_read_binary( grp, &grp->G,
( const unsigned char *) p, len ) ) != 0 )
if ((ret = mbedtls_ecp_point_read_binary( grp, &grp->G,
( const unsigned char *) p, len ) ) != 0 )
{
/*
* If we can't read the point because it's compressed, cheat by
* reading only the X coordinate and the parity bit of Y.
*/
if( ret != MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ||
( p[0] != 0x02 && p[0] != 0x03 ) ||
len != mbedtls_mpi_size( &grp->P ) + 1 ||
mbedtls_mpi_read_binary( &grp->G.X, p + 1, len - 1 ) != 0 ||
mbedtls_mpi_lset( &grp->G.Y, p[0] - 2 ) != 0 ||
mbedtls_mpi_lset( &grp->G.Z, 1 ) != 0 )
{
if (ret != MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE
|| ( p[0] != 0x02 && p[0] != 0x03 )
|| len != mbedtls_mpi_size( &grp->P ) + 1
|| mbedtls_mpi_read_binary( &grp->G.X, p + 1, len - 1 ) != 0
|| mbedtls_mpi_lset( &grp->G.Y, p[0] - 2 ) != 0
|| mbedtls_mpi_lset( &grp->G.Z, 1 ) != 0 )
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT );
}
}
p += len;
@ -342,16 +340,15 @@ static int pk_group_from_specified( const mbedtls_asn1_buf *params, mbedtls_ecp_
/*
* order INTEGER
*/
if( ( ret = mbedtls_asn1_get_mpi( &p, end, &grp->N ) ) != 0 )
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
if ((ret = mbedtls_asn1_get_mpi( &p, end, &grp->N)) != 0)
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret);
grp->nbits = mbedtls_mpi_bitlen( &grp->N );
/*
* Allow optional elements by purposefully not enforcing p == end here.
*/
return( 0 );
return 0;
}
/*
@ -519,12 +516,12 @@ static int pk_get_rsapubkey( unsigned char **p,
return( MBEDTLS_ERR_PK_INVALID_PUBKEY +
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
if( ( ret = mbedtls_rsa_check_pubkey( rsa ) ) != 0 )
return( MBEDTLS_ERR_PK_INVALID_PUBKEY );
if( (mbedtls_rsa_check_pubkey(rsa)) != 0 )
return MBEDTLS_ERR_PK_INVALID_PUBKEY;
rsa->len = mbedtls_mpi_size( &rsa->N );
return( 0 );
return 0;
}
#endif /* MBEDTLS_RSA_C */
@ -1185,22 +1182,18 @@ int mbedtls_pk_parse_key( mbedtls_pk_context *pk,
* error
*/
#if defined(MBEDTLS_PKCS12_C) || defined(MBEDTLS_PKCS5_C)
if( ( ret = pk_parse_key_pkcs8_encrypted_der( pk, key, keylen,
pwd, pwdlen ) ) == 0 )
{
return( 0 );
}
if( ( ret = pk_parse_key_pkcs8_encrypted_der(pk, key, keylen,
pwd, pwdlen ) ) == 0 )
return 0;
mbedtls_pk_free( pk );
if( ret == MBEDTLS_ERR_PK_PASSWORD_MISMATCH )
{
return( ret );
}
return ret;
#endif /* MBEDTLS_PKCS12_C || MBEDTLS_PKCS5_C */
if( ( ret = pk_parse_key_pkcs8_unencrypted_der( pk, key, keylen ) ) == 0 )
return( 0 );
if ((pk_parse_key_pkcs8_unencrypted_der( pk, key, keylen)) == 0)
return 0;
mbedtls_pk_free( pk );
@ -1208,11 +1201,9 @@ int mbedtls_pk_parse_key( mbedtls_pk_context *pk,
if( ( pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == NULL )
return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG );
if( ( ret = mbedtls_pk_setup( pk, pk_info ) ) != 0 ||
( ret = pk_parse_key_pkcs1_der( mbedtls_pk_rsa( *pk ), key, keylen ) ) == 0 )
{
return( 0 );
}
if( (mbedtls_pk_setup(pk, pk_info)) != 0
|| (pk_parse_key_pkcs1_der( mbedtls_pk_rsa(*pk), key, keylen)) == 0)
return 0;
mbedtls_pk_free( pk );
#endif /* MBEDTLS_RSA_C */
@ -1221,11 +1212,9 @@ int mbedtls_pk_parse_key( mbedtls_pk_context *pk,
if( ( pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_ECKEY ) ) == NULL )
return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG );
if( ( ret = mbedtls_pk_setup( pk, pk_info ) ) != 0 ||
( ret = pk_parse_key_sec1_der( mbedtls_pk_ec( *pk ), key, keylen ) ) == 0 )
{
return( 0 );
}
if( (mbedtls_pk_setup( pk, pk_info)) != 0
|| (pk_parse_key_sec1_der( mbedtls_pk_ec( *pk ), key, keylen)) == 0 )
return 0;
mbedtls_pk_free( pk );
#endif /* MBEDTLS_ECP_C */

10
deps/mbedtls/rsa.c vendored
View File

@ -1485,21 +1485,21 @@ int mbedtls_rsa_rsassa_pkcs1_v15_verify( mbedtls_rsa_context *ctx,
* Bleichenbacher's forgery attack against lax PKCS#1v1.5 verification.
*/
p0 = p;
if( ( ret = mbedtls_asn1_get_tag( &p, end, &asn1_len,
if( ( mbedtls_asn1_get_tag( &p, end, &asn1_len,
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
if( p != p0 + 2 || asn1_len + 2 != len )
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
p0 = p;
if( ( ret = mbedtls_asn1_get_tag( &p, end, &asn1_len,
if( ( mbedtls_asn1_get_tag( &p, end, &asn1_len,
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
if( p != p0 + 2 || asn1_len + 6 + hashlen != len )
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
p0 = p;
if( ( ret = mbedtls_asn1_get_tag( &p, end, &oid.len, MBEDTLS_ASN1_OID ) ) != 0 )
if( ( mbedtls_asn1_get_tag( &p, end, &oid.len, MBEDTLS_ASN1_OID ) ) != 0 )
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
if( p != p0 + 2 )
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
@ -1517,13 +1517,13 @@ int mbedtls_rsa_rsassa_pkcs1_v15_verify( mbedtls_rsa_context *ctx,
* assume the algorithm parameters must be NULL
*/
p0 = p;
if( ( ret = mbedtls_asn1_get_tag( &p, end, &asn1_len, MBEDTLS_ASN1_NULL ) ) != 0 )
if( ( mbedtls_asn1_get_tag( &p, end, &asn1_len, MBEDTLS_ASN1_NULL ) ) != 0 )
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
if( p != p0 + 2 )
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
p0 = p;
if( ( ret = mbedtls_asn1_get_tag( &p, end, &asn1_len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 )
if( ( mbedtls_asn1_get_tag( &p, end, &asn1_len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 )
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
if( p != p0 + 2 || asn1_len != hashlen )
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );

View File

@ -300,8 +300,8 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain,
* signatureAlgorithm AlgorithmIdentifier,
* signatureValue BIT STRING }
*/
if( ( ret = mbedtls_asn1_get_tag( &p, end, &len,
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
if( ( mbedtls_asn1_get_tag(&p, end, &len,
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0 )
{
mbedtls_x509_crl_free( crl );
return( MBEDTLS_ERR_X509_INVALID_FORMAT );
@ -350,9 +350,9 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain,
crl->version++;
if( ( ret = mbedtls_x509_get_sig_alg( &crl->sig_oid, &sig_params1,
if( ( mbedtls_x509_get_sig_alg(&crl->sig_oid, &sig_params1,
&crl->sig_md, &crl->sig_pk,
&crl->sig_opts ) ) != 0 )
&crl->sig_opts)) != 0 )
{
mbedtls_x509_crl_free( crl );
return( MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG );

View File

@ -682,7 +682,7 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt, const unsigned char *
* signatureAlgorithm AlgorithmIdentifier,
* signatureValue BIT STRING }
*/
if( ( ret = mbedtls_asn1_get_tag( &p, end, &len,
if( ( mbedtls_asn1_get_tag( &p, end, &len,
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
{
mbedtls_x509_crt_free( crt );

View File

@ -120,7 +120,7 @@ int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr,
* signature BIT STRING
* }
*/
if( ( ret = mbedtls_asn1_get_tag( &p, end, &len,
if( ( mbedtls_asn1_get_tag( &p, end, &len,
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
{
mbedtls_x509_csr_free( csr );
@ -226,7 +226,7 @@ int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr,
return( ret );
}
if( ( ret = mbedtls_x509_get_sig_alg( &csr->sig_oid, &sig_params,
if( (mbedtls_x509_get_sig_alg( &csr->sig_oid, &sig_params,
&csr->sig_md, &csr->sig_pk,
&csr->sig_opts ) ) != 0 )
{
@ -247,7 +247,7 @@ int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr,
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
}
return( 0 );
return 0;
}
/*

View File

@ -132,14 +132,14 @@ bool d3d_compile(const char* src, size_t len,
src, len, src_name, NULL, NULL,
entrypoint, target, compileflags, 0, out, &error_msg)))
{
if (error_msg)
const char* msg = (const char*)error_msg->lpVtbl->GetBufferPointer(error_msg);
if (msg)
{
const char* msg = (const char*)error_msg->lpVtbl->GetBufferPointer(error_msg);
RARCH_ERR("D3DCompile failed: %s.\n", msg);
/* Place a breakpoint here, if you want,
to see shader compilation issues */
Release(error_msg);
}
Release(error_msg);
return false;
}
@ -160,12 +160,10 @@ bool d3d_compile_from_file(LPCWSTR filename,
filename, NULL, NULL, entrypoint,
target, compileflags, 0, out, &error_msg)))
{
if (error_msg)
{
RARCH_ERR("D3DCompile failed: %s.\n",
(const char*)error_msg->lpVtbl->GetBufferPointer(error_msg));
Release(error_msg);
}
const char* msg = (const char*)error_msg->lpVtbl->GetBufferPointer(error_msg);
if (msg)
RARCH_ERR("D3DCompile failed: %s.\n", msg);
Release(error_msg);
return false;
}

View File

@ -31,6 +31,7 @@
#include <windows.h>
#endif /* !defined(_XBOX) */
#include <math.h>
#include <wchar.h>
#include <retro_miscellaneous.h>
#include <string/stdstring.h>

View File

@ -142,6 +142,7 @@ rxml_document_t *rxml_load_document_string(const char *str)
doc = (rxml_document_t*)malloc(sizeof(*doc));
if (!doc)
goto error;
doc->root_node = NULL;
yxml_init(&x, buf->xml, BUFSIZE);

View File

@ -593,7 +593,7 @@ static int general_push(menu_displaylist_info_t *info,
CHECK_SIZE(strlen(sysinfo.valid_extensions) + 1);
if (_len > 0)
newstr2[_len++] = '|';
_len += strlcpy(newstr2 + _len, sysinfo.valid_extensions, size - _len);
strlcpy(newstr2 + _len, sysinfo.valid_extensions, size - _len);
}
#endif

View File

@ -1585,7 +1585,7 @@ static int action_bind_sublabel_subsystem_load(
{
size_t _len = strlcat(buf, path_basename(content_get_subsystem_rom(j)), sizeof(buf));
if (j != content_get_subsystem_rom_id() - 1)
_len += strlcpy(buf + _len, "\n", sizeof(buf) - _len);
strlcpy(buf + _len, "\n", sizeof(buf) - _len);
}
if (!string_is_empty(buf))

View File

@ -2997,7 +2997,10 @@ static void ozone_draw_icon(
draw.pipeline_id = 0;
if (draw.height > 0 && draw.width > 0)
dispctx->draw(&draw, userdata, video_width, video_height);
{
if (dispctx && dispctx->draw)
dispctx->draw(&draw, userdata, video_width, video_height);
}
}
static int ozone_wiggle(ozone_handle_t* ozone, float t)

View File

@ -2790,14 +2790,14 @@ static void xmb_context_reset_horizontal_list(xmb_handle_t *xmb)
sizeof(sysname));
__len = fill_pathname_join_special(texturepath, iconpath, sysname,
sizeof(texturepath));
__len += strlcpy(texturepath + __len, ".png", sizeof(texturepath) - __len);
strlcpy(texturepath + __len, ".png", sizeof(texturepath) - __len);
/* If the playlist icon doesn't exist return default */
if (!path_is_valid(texturepath))
{
__len = fill_pathname_join_special(texturepath, iconpath, "default",
sizeof(texturepath));
__len += strlcpy(texturepath + __len, ".png", sizeof(texturepath) - __len);
strlcpy(texturepath + __len, ".png", sizeof(texturepath) - __len);
}
ti.width = 0;

View File

@ -4813,11 +4813,13 @@ bool command_event(enum event_command cmd, void *data)
sizeof(tmp_netplay_server)))
{
netplay_server = tmp_netplay_server;
netplay_session = strdup(tmp_netplay_session);
if (p_rarch->connect_mitm_id)
netplay_session = strdup(p_rarch->connect_mitm_id);
else
netplay_session = strdup(tmp_netplay_session);
}
if (p_rarch->connect_mitm_id)
netplay_session = strdup(p_rarch->connect_mitm_id);
else if (p_rarch->connect_mitm_id)
netplay_session = strdup(p_rarch->connect_mitm_id);
if (p_rarch->connect_host)
{

View File

@ -141,8 +141,8 @@ static unsigned input_autoconfigure_get_config_file_affinity(
/* Parse config file */
_len = strlcpy(config_key, "input_vendor_id",
sizeof(config_key));
_len += strlcpy(config_key + _len, config_key_postfix,
sizeof(config_key) - _len);
strlcpy(config_key + _len, config_key_postfix,
sizeof(config_key) - _len);
if (config_get_int(config, config_key, &tmp_int))
config_vid = (uint16_t)tmp_int;
@ -178,8 +178,8 @@ static unsigned input_autoconfigure_get_config_file_affinity(
/* Check for matching device name */
_len = strlcpy(config_key, "input_device",
sizeof(config_key));
_len += strlcpy(config_key + _len, config_key_postfix,
sizeof(config_key) - _len);
strlcpy(config_key + _len, config_key_postfix,
sizeof(config_key) - _len);
if ( (entry = config_get_entry(config, config_key))
&& !string_is_empty(entry->value)
&& string_is_equal(entry->value,