1
0
Fork 0
mirror of https://github.com/DarkMatterCore/nxdumptool.git synced 2024-11-26 04:02:11 +00:00

Replace unnecessary strlen() calls with pointer dereferences or calculations using info available at runtime (when possible).

This should probably improve performance a little bit in certain sections.
This commit is contained in:
Pablo Curiel 2020-10-14 20:06:53 -04:00
parent 6f4cb98033
commit bd98fd4c32
14 changed files with 70 additions and 57 deletions

View file

@ -54,7 +54,7 @@ bool certRetrieveCertificateByName(Certificate *dst, const char *name)
bool ret = false;
if (!dst || !name || !strlen(name))
if (!dst || !name || !*name)
{
LOGFILE("Invalid parameters!");
goto end;
@ -99,7 +99,7 @@ end:
u8 *certGenerateRawCertificateChainBySignatureIssuer(const char *issuer, u64 *out_size)
{
if (!issuer || !strlen(issuer) || !out_size)
if (!issuer || !*issuer || !out_size)
{
LOGFILE("Invalid parameters!");
return NULL;
@ -350,7 +350,7 @@ static bool _certRetrieveCertificateChainBySignatureIssuer(CertificateChain *dst
static u32 certGetCertificateCountInSignatureIssuer(const char *issuer)
{
if (!issuer || !strlen(issuer)) return 0;
if (!issuer || !*issuer) return 0;
u32 count = 0;
char issuer_copy[0x40] = {0};

View file

@ -41,7 +41,7 @@ static const char *cnmtGetRequiredTitleTypeString(u8 content_meta_type);
bool cnmtInitializeContext(ContentMetaContext *out, NcaContext *nca_ctx)
{
if (!out || !nca_ctx || !strlen(nca_ctx->content_id_str) || nca_ctx->content_type != NcmContentType_Meta || nca_ctx->content_size < NCA_FULL_HEADER_LENGTH || \
if (!out || !nca_ctx || !*(nca_ctx->content_id_str) || nca_ctx->content_type != NcmContentType_Meta || nca_ctx->content_size < NCA_FULL_HEADER_LENGTH || \
(nca_ctx->storage_id != NcmStorageId_GameCard && !nca_ctx->ncm_storage) || (nca_ctx->storage_id == NcmStorageId_GameCard && !nca_ctx->gamecard_offset) || \
nca_ctx->header.content_type != NcaContentType_Meta || !out)
{

View file

@ -437,7 +437,7 @@ bool gamecardGetEntryInfoFromHashFileSystemPartitionByIndex(u8 hfs_partition_typ
if (out_name)
{
entry_name = gamecardGetHashFileSystemEntryNameByIndex(fs_header, idx);
if (!entry_name || !strlen(entry_name))
if (!entry_name || !*entry_name)
{
LOGFILE("Invalid hash FS partition entry name!");
goto end;

View file

@ -481,7 +481,7 @@ static bool keysParseHexKey(u8 *out, const char *key, const char *value, u32 siz
u32 hex_str_len = (2 * size);
size_t value_len = 0;
if (!out || !key || !strlen(key) || !value || !(value_len = strlen(value)) || !size)
if (!out || !key || !*key || !value || !(value_len = strlen(value)) || !size)
{
LOGFILE("Invalid parameters!");
return false;

View file

@ -24,7 +24,7 @@
bool legalInfoInitializeContext(LegalInfoContext *out, NcaContext *nca_ctx)
{
if (!out || !nca_ctx || !strlen(nca_ctx->content_id_str) || nca_ctx->content_type != NcmContentType_LegalInformation || nca_ctx->content_size < NCA_FULL_HEADER_LENGTH || \
if (!out || !nca_ctx || !*(nca_ctx->content_id_str) || nca_ctx->content_type != NcmContentType_LegalInformation || nca_ctx->content_size < NCA_FULL_HEADER_LENGTH || \
(nca_ctx->storage_id != NcmStorageId_GameCard && !nca_ctx->ncm_storage) || (nca_ctx->storage_id == NcmStorageId_GameCard && !nca_ctx->gamecard_offset) || \
nca_ctx->header.content_type != NcaContentType_Manual || !out)
{

View file

@ -197,7 +197,7 @@ static bool nacpAddU64FieldToAuthoringToolXml(char **xml_buf, u64 *xml_buf_size,
bool nacpInitializeContext(NacpContext *out, NcaContext *nca_ctx)
{
if (!out || !nca_ctx || !strlen(nca_ctx->content_id_str) || nca_ctx->content_type != NcmContentType_Control || nca_ctx->content_size < NCA_FULL_HEADER_LENGTH || \
if (!out || !nca_ctx || !*(nca_ctx->content_id_str) || nca_ctx->content_type != NcmContentType_Control || nca_ctx->content_size < NCA_FULL_HEADER_LENGTH || \
(nca_ctx->storage_id != NcmStorageId_GameCard && !nca_ctx->ncm_storage) || (nca_ctx->storage_id == NcmStorageId_GameCard && !nca_ctx->gamecard_offset) || \
nca_ctx->header.content_type != NcaContentType_Control || !out)
{
@ -364,7 +364,7 @@ bool nacpGenerateAuthoringToolXml(NacpContext *nacp_ctx, u32 version, u32 requir
for(i = 0, count = 0; i < NacpLanguage_Count; i++)
{
NacpTitle *title = &(nacp->title[i]);
if (!strlen(title->name) || !strlen(title->publisher)) continue;
if (!*(title->name) || !*(title->publisher)) continue;
if (!utilsAppendFormattedStringToBuffer(&xml_buf, &xml_buf_size, \
" <Title>\n" \
@ -856,19 +856,19 @@ NX_INLINE bool nacpCheckBitflagField(const void *flag, u8 flag_bitcount, u8 idx)
static bool nacpAddStringFieldToAuthoringToolXml(char **xml_buf, u64 *xml_buf_size, const char *tag_name, const char *value)
{
if (!xml_buf || !xml_buf_size || !tag_name || !strlen(tag_name) || !value)
if (!xml_buf || !xml_buf_size || !tag_name || !*tag_name || !value)
{
LOGFILE("Invalid parameters!");
return false;
}
return (strlen(value) ? utilsAppendFormattedStringToBuffer(xml_buf, xml_buf_size, " <%s>%s</%s>\n", tag_name, value, tag_name) : \
return (*value ? utilsAppendFormattedStringToBuffer(xml_buf, xml_buf_size, " <%s>%s</%s>\n", tag_name, value, tag_name) : \
utilsAppendFormattedStringToBuffer(xml_buf, xml_buf_size, " <%s />\n", tag_name));
}
static bool nacpAddEnumFieldToAuthoringToolXml(char **xml_buf, u64 *xml_buf_size, const char *tag_name, u8 value, NacpStringFunction str_func)
{
if (!xml_buf || !xml_buf_size || !tag_name || !strlen(tag_name) || !str_func)
if (!xml_buf || !xml_buf_size || !tag_name || !*tag_name || !str_func)
{
LOGFILE("Invalid parameters!");
return false;
@ -883,7 +883,7 @@ static bool nacpAddBitflagFieldToAuthoringToolXml(char **xml_buf, u64 *xml_buf_s
const u8 *flag_u8 = (const u8*)flag;
bool success = false, empty_flag = true;
if (!xml_buf || !xml_buf_size || !tag_name || !strlen(tag_name) || !flag || !flag_width || (flag_width > 1 && !IS_POWER_OF_TWO(flag_width)) || flag_width > 0x10 || \
if (!xml_buf || !xml_buf_size || !tag_name || !*tag_name || !flag || !flag_width || (flag_width > 1 && !IS_POWER_OF_TWO(flag_width)) || flag_width > 0x10 || \
(flag_bitcount = (flag_width * 8)) < max_flag_idx || !str_func)
{
LOGFILE("Invalid parameters!");
@ -922,7 +922,7 @@ end:
static bool nacpAddU16FieldToAuthoringToolXml(char **xml_buf, u64 *xml_buf_size, const char *tag_name, u16 value, bool hex)
{
if (!xml_buf || !xml_buf_size || !tag_name || !strlen(tag_name))
if (!xml_buf || !xml_buf_size || !tag_name || !*tag_name)
{
LOGFILE("Invalid parameters!");
return false;
@ -934,7 +934,7 @@ static bool nacpAddU16FieldToAuthoringToolXml(char **xml_buf, u64 *xml_buf_size,
static bool nacpAddU32FieldToAuthoringToolXml(char **xml_buf, u64 *xml_buf_size, const char *tag_name, u32 value)
{
if (!xml_buf || !xml_buf_size || !tag_name || !strlen(tag_name))
if (!xml_buf || !xml_buf_size || !tag_name || !*tag_name)
{
LOGFILE("Invalid parameters!");
return false;
@ -945,7 +945,7 @@ static bool nacpAddU32FieldToAuthoringToolXml(char **xml_buf, u64 *xml_buf_size,
static bool nacpAddU64FieldToAuthoringToolXml(char **xml_buf, u64 *xml_buf_size, const char *tag_name, u64 value)
{
if (!xml_buf || !xml_buf_size || !tag_name || !strlen(tag_name))
if (!xml_buf || !xml_buf_size || !tag_name || !*tag_name)
{
LOGFILE("Invalid parameters!");
return false;

View file

@ -248,7 +248,7 @@ bool ncaInitializeContext(NcaContext *out, u8 storage_id, u8 hfs_partition_type,
bool ncaReadContentFile(NcaContext *ctx, void *out, u64 read_size, u64 offset)
{
if (!ctx || !strlen(ctx->content_id_str) || (ctx->storage_id != NcmStorageId_GameCard && !ctx->ncm_storage) || (ctx->storage_id == NcmStorageId_GameCard && !ctx->gamecard_offset) || !out || \
if (!ctx || !*(ctx->content_id_str) || (ctx->storage_id != NcmStorageId_GameCard && !ctx->ncm_storage) || (ctx->storage_id == NcmStorageId_GameCard && !ctx->gamecard_offset) || !out || \
!read_size || offset >= ctx->content_size || (offset + read_size) > ctx->content_size)
{
LOGFILE("Invalid parameters!");
@ -297,7 +297,7 @@ bool ncaGenerateHierarchicalSha256Patch(NcaFsSectionContext *ctx, const void *da
void ncaWriteHierarchicalSha256PatchToMemoryBuffer(NcaContext *ctx, NcaHierarchicalSha256Patch *patch, void *buf, u64 buf_size, u64 buf_offset)
{
if (!ctx || !strlen(ctx->content_id_str) || ctx->content_size < NCA_FULL_HEADER_LENGTH || !patch || memcmp(patch->content_id.c, ctx->content_id.c, 0x10) != 0 || !patch->hash_region_count || \
if (!ctx || !*(ctx->content_id_str) || ctx->content_size < NCA_FULL_HEADER_LENGTH || !patch || memcmp(patch->content_id.c, ctx->content_id.c, 0x10) != 0 || !patch->hash_region_count || \
patch->hash_region_count > NCA_HIERARCHICAL_SHA256_MAX_REGION_COUNT || !buf || !buf_size || buf_offset >= ctx->content_size || (buf_offset + buf_size) > ctx->content_size) return;
for(u32 i = 0; i < patch->hash_region_count; i++)
@ -314,7 +314,7 @@ bool ncaGenerateHierarchicalIntegrityPatch(NcaFsSectionContext *ctx, const void
void ncaWriteHierarchicalIntegrityPatchToMemoryBuffer(NcaContext *ctx, NcaHierarchicalIntegrityPatch *patch, void *buf, u64 buf_size, u64 buf_offset)
{
if (!ctx || !strlen(ctx->content_id_str) || ctx->content_size < NCA_FULL_HEADER_LENGTH || !patch || memcmp(patch->content_id.c, ctx->content_id.c, 0x10) != 0 || !buf || !buf_size || \
if (!ctx || !*(ctx->content_id_str) || ctx->content_size < NCA_FULL_HEADER_LENGTH || !patch || memcmp(patch->content_id.c, ctx->content_id.c, 0x10) != 0 || !buf || !buf_size || \
buf_offset >= ctx->content_size || (buf_offset + buf_size) > ctx->content_size) return;
for(u32 i = 0; i < NCA_IVFC_LEVEL_COUNT; i++)
@ -349,7 +349,7 @@ void ncaRemoveTitlekeyCrypto(NcaContext *ctx)
bool ncaEncryptHeader(NcaContext *ctx)
{
if (!ctx || !strlen(ctx->content_id_str) || ctx->content_size < NCA_FULL_HEADER_LENGTH)
if (!ctx || !*(ctx->content_id_str) || ctx->content_size < NCA_FULL_HEADER_LENGTH)
{
LOGFILE("Invalid NCA context!");
return false;
@ -413,7 +413,7 @@ void ncaWriteEncryptedHeaderDataToMemoryBuffer(NcaContext *ctx, void *buf, u64 b
{
/* Return right away if we're dealing with invalid parameters, or if the buffer data is not part of the range covered by the encrypted header data (NCA2/3 optimization, last condition). */
/* In order to avoid taking up too much execution time when this function is called (ideally inside a loop), we won't use ncaIsHeaderDirty() here. Let the user take care of it instead. */
if (!ctx || !strlen(ctx->content_id_str) || ctx->content_size < NCA_FULL_HEADER_LENGTH || !buf || !buf_size || buf_offset >= ctx->content_size || \
if (!ctx || !*(ctx->content_id_str) || ctx->content_size < NCA_FULL_HEADER_LENGTH || !buf || !buf_size || buf_offset >= ctx->content_size || \
(buf_offset + buf_size) > ctx->content_size || (ctx->format_version != NcaVersion_Nca0 && buf_offset >= NCA_FULL_HEADER_LENGTH)) return;
/* Attempt to write the NCA header. */
@ -477,7 +477,7 @@ NX_INLINE bool ncaIsFsInfoEntryValid(NcaFsInfo *fs_info)
static bool ncaReadDecryptedHeader(NcaContext *ctx)
{
if (!ctx || !strlen(ctx->content_id_str) || ctx->content_size < NCA_FULL_HEADER_LENGTH)
if (!ctx || !*(ctx->content_id_str) || ctx->content_size < NCA_FULL_HEADER_LENGTH)
{
LOGFILE("Invalid NCA context!");
return false;
@ -746,7 +746,7 @@ static bool _ncaReadFsSection(NcaFsSectionContext *ctx, void *out, u64 read_size
u64 block_start_offset = 0, block_end_offset = 0, block_size = 0;
u64 data_start_offset = 0, chunk_size = 0, out_chunk_size = 0;
if (!strlen(nca_ctx->content_id_str) || (nca_ctx->storage_id != NcmStorageId_GameCard && !nca_ctx->ncm_storage) || (nca_ctx->storage_id == NcmStorageId_GameCard && !nca_ctx->gamecard_offset) || \
if (!*(nca_ctx->content_id_str) || (nca_ctx->storage_id != NcmStorageId_GameCard && !nca_ctx->ncm_storage) || (nca_ctx->storage_id == NcmStorageId_GameCard && !nca_ctx->gamecard_offset) || \
(nca_ctx->format_version != NcaVersion_Nca0 && nca_ctx->format_version != NcaVersion_Nca2 && nca_ctx->format_version != NcaVersion_Nca3) || content_offset >= nca_ctx->content_size || \
(content_offset + read_size) > nca_ctx->content_size)
{
@ -865,7 +865,7 @@ static bool _ncaReadAesCtrExStorageFromBktrSection(NcaFsSectionContext *ctx, voi
u64 block_start_offset = 0, block_end_offset = 0, block_size = 0;
u64 data_start_offset = 0, chunk_size = 0, out_chunk_size = 0;
if (!strlen(nca_ctx->content_id_str) || (nca_ctx->storage_id != NcmStorageId_GameCard && !nca_ctx->ncm_storage) || (nca_ctx->storage_id == NcmStorageId_GameCard && !nca_ctx->gamecard_offset) || \
if (!*(nca_ctx->content_id_str) || (nca_ctx->storage_id != NcmStorageId_GameCard && !nca_ctx->ncm_storage) || (nca_ctx->storage_id == NcmStorageId_GameCard && !nca_ctx->gamecard_offset) || \
content_offset >= nca_ctx->content_size || (content_offset + read_size) > nca_ctx->content_size)
{
LOGFILE("Invalid NCA header parameters!");
@ -1187,7 +1187,7 @@ static void *_ncaGenerateEncryptedFsSectionBlock(NcaFsSectionContext *ctx, const
u64 block_start_offset = 0, block_end_offset = 0, block_size = 0;
u64 plain_chunk_offset = 0;
if (!strlen(nca_ctx->content_id_str) || (nca_ctx->storage_id != NcmStorageId_GameCard && !nca_ctx->ncm_storage) || (nca_ctx->storage_id == NcmStorageId_GameCard && !nca_ctx->gamecard_offset) || \
if (!*(nca_ctx->content_id_str) || (nca_ctx->storage_id != NcmStorageId_GameCard && !nca_ctx->ncm_storage) || (nca_ctx->storage_id == NcmStorageId_GameCard && !nca_ctx->gamecard_offset) || \
(nca_ctx->format_version != NcaVersion_Nca0 && nca_ctx->format_version != NcaVersion_Nca2 && nca_ctx->format_version != NcaVersion_Nca3) || content_offset >= nca_ctx->content_size || \
(content_offset + data_size) > nca_ctx->content_size)
{

View file

@ -52,7 +52,7 @@ bool nsoInitializeContext(NsoContext *out, PartitionFileSystemContext *pfs_ctx,
out->pfs_entry = pfs_entry;
/* Get entry filename. */
if (!(out->nso_filename = pfsGetEntryName(pfs_ctx, pfs_entry)) || !strlen(out->nso_filename))
if (!(out->nso_filename = pfsGetEntryName(pfs_ctx, pfs_entry)) || !*(out->nso_filename))
{
LOGFILE("Invalid Partition FS entry filename!");
goto end;

View file

@ -54,7 +54,7 @@ static bool programInfoAddFsAccessControlDataToAuthoringToolXml(char **xml_buf,
bool programInfoInitializeContext(ProgramInfoContext *out, NcaContext *nca_ctx)
{
if (!out || !nca_ctx || !strlen(nca_ctx->content_id_str) || nca_ctx->content_type != NcmContentType_Program || nca_ctx->content_size < NCA_FULL_HEADER_LENGTH || \
if (!out || !nca_ctx || !*(nca_ctx->content_id_str) || nca_ctx->content_type != NcmContentType_Program || nca_ctx->content_size < NCA_FULL_HEADER_LENGTH || \
(nca_ctx->storage_id != NcmStorageId_GameCard && !nca_ctx->ncm_storage) || (nca_ctx->storage_id == NcmStorageId_GameCard && !nca_ctx->gamecard_offset) || \
nca_ctx->header.content_type != NcaContentType_Program || !out)
{
@ -352,8 +352,8 @@ static bool programInfoAddNsoApiListToAuthoringToolXml(char **xml_buf, u64 *xml_
char *sdk_entry = NULL, *sdk_entry_vender = NULL, *sdk_entry_name = NULL;
bool success = false, api_list_exists = false;
if (!xml_buf || !xml_buf_size || !program_info_ctx || !program_info_ctx->nso_count || !program_info_ctx->nso_ctx || !api_list_tag || !strlen(api_list_tag) || !api_entry_prefix || \
!strlen(api_entry_prefix) || !sdk_prefix || !(sdk_prefix_len = strlen(sdk_prefix)))
if (!xml_buf || !xml_buf_size || !program_info_ctx || !program_info_ctx->nso_count || !program_info_ctx->nso_ctx || !api_list_tag || !*api_list_tag || !api_entry_prefix || \
!*api_entry_prefix || !sdk_prefix || !(sdk_prefix_len = strlen(sdk_prefix)))
{
LOGFILE("Invalid parameters!");
return false;
@ -363,7 +363,7 @@ static bool programInfoAddNsoApiListToAuthoringToolXml(char **xml_buf, u64 *xml_
for(u32 i = 0; i < program_info_ctx->nso_count; i++)
{
NsoContext *nso_ctx = &(program_info_ctx->nso_ctx[i]);
if (!nso_ctx->nso_filename || !strlen(nso_ctx->nso_filename) || !nso_ctx->rodata_api_info_section || !nso_ctx->rodata_api_info_section_size) continue;
if (!nso_ctx->nso_filename || !*(nso_ctx->nso_filename) || !nso_ctx->rodata_api_info_section || !nso_ctx->rodata_api_info_section_size) continue;
for(u64 j = 0; j < nso_ctx->rodata_api_info_section_size; j++)
{
@ -394,7 +394,7 @@ static bool programInfoAddNsoApiListToAuthoringToolXml(char **xml_buf, u64 *xml_
for(u32 i = 0; i < program_info_ctx->nso_count; i++)
{
NsoContext *nso_ctx = &(program_info_ctx->nso_ctx[i]);
if (!nso_ctx->nso_filename || !strlen(nso_ctx->nso_filename) || !nso_ctx->rodata_api_info_section || !nso_ctx->rodata_api_info_section_size) continue;
if (!nso_ctx->nso_filename || !*(nso_ctx->nso_filename) || !nso_ctx->rodata_api_info_section || !nso_ctx->rodata_api_info_section_size) continue;
for(u64 j = 0; j < nso_ctx->rodata_api_info_section_size; j++)
{
@ -447,13 +447,13 @@ static bool programInfoIsApiInfoEntryValid(const char *sdk_prefix, size_t sdk_pr
static bool programInfoAddStringFieldToAuthoringToolXml(char **xml_buf, u64 *xml_buf_size, const char *tag_name, const char *value)
{
if (!xml_buf || !xml_buf_size || !tag_name || !strlen(tag_name))
if (!xml_buf || !xml_buf_size || !tag_name || !*tag_name)
{
LOGFILE("Invalid parameters!");
return false;
}
return ((value && strlen(value)) ? utilsAppendFormattedStringToBuffer(xml_buf, xml_buf_size, " <%s>%s</%s>\n", tag_name, value, tag_name) : \
return ((value && *value) ? utilsAppendFormattedStringToBuffer(xml_buf, xml_buf_size, " <%s>%s</%s>\n", tag_name, value, tag_name) : \
utilsAppendFormattedStringToBuffer(xml_buf, xml_buf_size, " <%s />\n", tag_name));
}

View file

@ -421,13 +421,14 @@ bool romfsGeneratePathFromDirectoryEntry(RomFileSystemContext *ctx, RomFileSyste
dir_entries = tmp_dir_entries;
tmp_dir_entries = NULL;
if (!(dir_entries[dir_entries_count] = romfsGetDirectoryEntryByOffset(ctx, dir_offset)) || !dir_entries[dir_entries_count]->name_length)
RomFileSystemDirectoryEntry **cur_dir_entry = &(dir_entries[dir_entries_count]);
if (!(*cur_dir_entry = romfsGetDirectoryEntryByOffset(ctx, dir_offset)) || !(*cur_dir_entry)->name_length)
{
LOGFILE("Failed to retrieve directory entry!");
goto end;
}
path_len += (1 + dir_entries[dir_entries_count]->name_length);
path_len += (1 + (*cur_dir_entry)->name_length);
dir_entries_count++;
}
@ -439,12 +440,19 @@ bool romfsGeneratePathFromDirectoryEntry(RomFileSystemContext *ctx, RomFileSyste
/* Generate output path. */
*out_path = '\0';
path_len = 0;
for(u32 i = dir_entries_count; i > 0; i--)
{
RomFileSystemDirectoryEntry **cur_dir_entry = &(dir_entries[i - 1]);
strcat(out_path, "/");
strncat(out_path, dir_entries[i - 1]->name, dir_entries[i - 1]->name_length);
if (illegal_char_replace_type) utilsReplaceIllegalCharacters(out_path + (strlen(out_path) - dir_entries[i - 1]->name_length), \
illegal_char_replace_type == RomFileSystemPathIllegalCharReplaceType_KeepAsciiCharsOnly);
strncat(out_path, (*cur_dir_entry)->name, (*cur_dir_entry)->name_length);
path_len++;
if (illegal_char_replace_type) utilsReplaceIllegalCharacters(out_path + path_len, illegal_char_replace_type == RomFileSystemPathIllegalCharReplaceType_KeepAsciiCharsOnly);
path_len += (*cur_dir_entry)->name_length;
}
success = true;
@ -483,10 +491,15 @@ bool romfsGeneratePathFromFileEntry(RomFileSystemContext *ctx, RomFileSystemFile
}
/* Concatenate file entry name. */
if (file_entry->parent_offset) strcat(out_path, "/");
if (file_entry->parent_offset)
{
strcat(out_path, "/");
path_len++;
}
strncat(out_path, file_entry->name, file_entry->name_length);
if (illegal_char_replace_type) utilsReplaceIllegalCharacters(out_path + (strlen(out_path) - file_entry->name_length), \
illegal_char_replace_type == RomFileSystemPathIllegalCharReplaceType_KeepAsciiCharsOnly);
if (illegal_char_replace_type) utilsReplaceIllegalCharacters(out_path + path_len, illegal_char_replace_type == RomFileSystemPathIllegalCharReplaceType_KeepAsciiCharsOnly);
return true;
}

View file

@ -958,7 +958,7 @@ end:
bool save_hierarchical_file_table_find_path_recursive(hierarchical_save_file_table_ctx_t *ctx, save_entry_key_t *key, const char *path)
{
if (!ctx || !key || !path || !strlen(path))
if (!ctx || !key || !path || !*path)
{
LOGFILE("Invalid parameters!");
return false;
@ -991,7 +991,7 @@ bool save_hierarchical_file_table_find_path_recursive(hierarchical_save_file_tab
bool save_hierarchical_file_table_get_file_entry_by_path(hierarchical_save_file_table_ctx_t *ctx, const char *path, save_fs_list_entry_t *entry)
{
if (!ctx || !path || !strlen(path) || !entry)
if (!ctx || !path || !*path || !entry)
{
LOGFILE("Invalid parameters!");
return false;
@ -1719,7 +1719,7 @@ void save_free_contexts(save_ctx_t *ctx)
save_ctx_t *save_open_savefile(const char *path, u32 action)
{
if (!path || !strlen(path))
if (!path || !*path)
{
LOGFILE("Invalid savefile path!");
return NULL;
@ -1795,7 +1795,7 @@ void save_close_savefile(save_ctx_t *ctx)
bool save_get_fat_storage_from_file_entry_by_path(save_ctx_t *ctx, const char *path, allocation_table_storage_ctx_t *out_fat_storage, u64 *out_file_entry_size)
{
if (!ctx || !path || !strlen(path) || !out_fat_storage || !out_file_entry_size)
if (!ctx || !path || !*path || !out_fat_storage || !out_file_entry_size)
{
LOGFILE("Invalid file entry path!");
return false;

View file

@ -133,7 +133,7 @@ void servicesClose(void)
bool servicesCheckRunningServiceByName(const char *name)
{
if (!name || !strlen(name)) return false;
if (!name || !*name) return false;
Result rc = 0;
Handle handle = INVALID_HANDLE;
@ -156,7 +156,7 @@ bool servicesCheckInitializedServiceByName(const char *name)
bool ret = false;
if (!name || !strlen(name)) goto end;
if (!name || !*name) goto end;
size_t name_len = strlen(name);
@ -195,7 +195,7 @@ void servicesChangeHardwareClockRates(u32 cpu_rate, u32 mem_rate)
Result servicesAtmosphereHasService(bool *out_has_service, const char *name)
{
if (!out_has_service || !name || !strlen(name))
if (!out_has_service || !name || !*name)
{
LOGFILE("Invalid parameters!");
return MAKERESULT(Module_Libnx, LibnxError_IoError);

View file

@ -750,7 +750,7 @@ char *titleGenerateFileName(const TitleInfo *title_info, u8 name_convention, u8
/* Generate filename for this title. */
if (name_convention == TitleFileNameConvention_Full)
{
if (app_metadata && strlen(app_metadata->lang_entry.name))
if (app_metadata && *(app_metadata->lang_entry.name))
{
sprintf(title_name, "%s ", app_metadata->lang_entry.name);
if (illegal_char_replace_type) utilsReplaceIllegalCharacters(title_name, illegal_char_replace_type == TitleFileNameIllegalCharReplaceType_KeepAsciiCharsOnly);
@ -816,7 +816,7 @@ char *titleGenerateGameCardFileName(u8 name_convention, u8 illegal_char_replace_
{
if (cur_filename_len) strcat(app_name, " + ");
if (app_info->app_metadata && strlen(app_info->app_metadata->lang_entry.name))
if (app_info->app_metadata && *(app_info->app_metadata->lang_entry.name))
{
sprintf(app_name + strlen(app_name), "%s ", app_info->app_metadata->lang_entry.name);
if (illegal_char_replace_type) utilsReplaceIllegalCharacters(app_name, illegal_char_replace_type == TitleFileNameIllegalCharReplaceType_KeepAsciiCharsOnly);

View file

@ -342,7 +342,7 @@ void utilsWaitForButtonPress(u64 flag)
bool utilsAppendFormattedStringToBuffer(char **dst, size_t *dst_size, const char *fmt, ...)
{
if (!dst || !dst_size || !fmt || !strlen(fmt))
if (!dst || !dst_size || !fmt || !*fmt)
{
LOGFILE("Invalid parameters!");
return false;
@ -399,7 +399,7 @@ end:
void utilsWriteMessageToLogFile(const char *func_name, const char *fmt, ...)
{
if (!func_name || !strlen(func_name) || !fmt || !strlen(fmt)) return;
if (!func_name || !*func_name || !fmt || !*fmt) return;
mutexLock(&g_logfileMutex);
@ -427,7 +427,7 @@ end:
void utilsWriteMessageToLogBuffer(char **dst, size_t *dst_size, const char *func_name, const char *fmt, ...)
{
if (!dst || !dst_size || !func_name || !strlen(func_name) || !fmt || !strlen(fmt)) return;
if (!dst || !dst_size || !func_name || !*func_name || !fmt || !*fmt) return;
va_list args;
va_start(args, fmt);
@ -475,7 +475,7 @@ end:
void utilsWriteLogBufferToLogFile(const char *src)
{
if (!src || !strlen(src)) return;
if (!src || !*src) return;
mutexLock(&g_logfileMutex);
@ -621,7 +621,7 @@ bool utilsCommitSdCardFileSystemChanges(void)
bool utilsCheckIfFileExists(const char *path)
{
if (!path || !strlen(path)) return false;
if (!path || !*path) return false;
FILE *chkfile = fopen(path, "rb");
if (chkfile)
@ -635,7 +635,7 @@ bool utilsCheckIfFileExists(const char *path)
bool utilsCreateConcatenationFile(const char *path)
{
if (!path || !strlen(path))
if (!path || !*path)
{
LOGFILE("Invalid parameters!");
return false;
@ -821,7 +821,7 @@ static bool utilsGetDeviceFileSystemAndFilePathFromAbsolutePath(const char *path
FsFileSystem *fs = NULL;
char *name_end = NULL, *filepath = NULL, name[32] = {0};
if (!path || !strlen(path) || !(name_end = strchr(path, ':')) || (size_t)(name_end - path) >= MAX_ELEMENTS(name) || (!out_fs && !out_filepath) || \
if (!path || !*path || !(name_end = strchr(path, ':')) || (size_t)(name_end - path) >= MAX_ELEMENTS(name) || (!out_fs && !out_filepath) || \
(out_filepath && *(filepath = (name_end + 1)) != '/')) return false;
sprintf(name, "%.*s", (int)(name_end - path), path);