(Qt) Less strlcat

This commit is contained in:
libretroadmin 2023-06-20 19:26:02 +02:00
parent 60fb5dfc6e
commit e3db17bf2d
1 changed files with 38 additions and 34 deletions

View File

@ -2711,13 +2711,13 @@ void MainWindow::loadContent(const QHash<QString, QString> &contentHash)
QByteArray contentLabelArray; QByteArray contentLabelArray;
QByteArray contentDbNameArray; QByteArray contentDbNameArray;
QByteArray contentCrc32Array; QByteArray contentCrc32Array;
char contentDbNameFull[PATH_MAX_LENGTH]; char content_db_name_full[PATH_MAX_LENGTH];
char corePathCached[PATH_MAX_LENGTH]; char core_path_cached[PATH_MAX_LENGTH];
const char *corePath = NULL; const char *core_path = NULL;
const char *contentPath = NULL; const char *content_path = NULL;
const char *contentLabel = NULL; const char *content_label = NULL;
const char *contentDbName = NULL; const char *content_db_name = NULL;
const char *contentCrc32 = NULL; const char *content_crc32 = NULL;
#ifdef HAVE_MENU #ifdef HAVE_MENU
struct menu_state *menu_st = menu_state_get_ptr(); struct menu_state *menu_st = menu_state_get_ptr();
#endif #endif
@ -2725,8 +2725,8 @@ void MainWindow::loadContent(const QHash<QString, QString> &contentHash)
core_selection coreSelection = static_cast<core_selection>(coreMap.value("core_selection").toInt()); core_selection coreSelection = static_cast<core_selection>(coreMap.value("core_selection").toInt());
core_info_t *coreInfo = NULL; core_info_t *coreInfo = NULL;
contentDbNameFull[0] = '\0'; content_db_name_full[0] = '\0';
corePathCached[0] = '\0'; core_path_cached[0] = '\0';
if (m_pendingRun) if (m_pendingRun)
coreSelection = CORE_SELECTION_CURRENT; coreSelection = CORE_SELECTION_CURRENT;
@ -2798,8 +2798,8 @@ void MainWindow::loadContent(const QHash<QString, QString> &contentHash)
if (!defaultCorePath.isEmpty()) if (!defaultCorePath.isEmpty())
{ {
corePathArray = defaultCorePath.toUtf8(); corePathArray = defaultCorePath.toUtf8();
contentPathArray = contentHash["path"].toUtf8(); contentPathArray = contentHash["path"].toUtf8();
contentLabelArray = contentHash["label_noext"].toUtf8(); contentLabelArray = contentHash["label_noext"].toUtf8();
} }
@ -2812,41 +2812,41 @@ void MainWindow::loadContent(const QHash<QString, QString> &contentHash)
contentDbNameArray = contentHash["db_name"].toUtf8(); contentDbNameArray = contentHash["db_name"].toUtf8();
contentCrc32Array = contentHash["crc32"].toUtf8(); contentCrc32Array = contentHash["crc32"].toUtf8();
corePath = corePathArray.constData(); core_path = corePathArray.constData();
contentPath = contentPathArray.constData(); content_path = contentPathArray.constData();
contentLabel = contentLabelArray.constData(); content_label = contentLabelArray.constData();
contentDbName = contentDbNameArray.constData(); content_db_name = contentDbNameArray.constData();
contentCrc32 = contentCrc32Array.constData(); content_crc32 = contentCrc32Array.constData();
/* Search for specified core - ensures path /* Search for specified core - ensures path
* is 'sanitised' */ * is 'sanitised' */
if (core_info_find(corePath, &coreInfo) && if ( core_info_find(core_path, &coreInfo)
!string_is_empty(coreInfo->path)) && !string_is_empty(coreInfo->path))
corePath = coreInfo->path; core_path = coreInfo->path;
/* If a core is currently running, the following /* If a core is currently running, the following
* call of 'command_event(CMD_EVENT_UNLOAD_CORE, NULL)' * call of 'command_event(CMD_EVENT_UNLOAD_CORE, NULL)'
* will free the global core_info struct, which will * will free the global core_info struct, which will
* in turn free the pointer referenced by coreInfo->path. * in turn free the pointer referenced by coreInfo->path.
* This will invalidate corePath, so we have to cache * This will invalidate core_path, so we have to cache
* its current value here. */ * its current value here. */
if (!string_is_empty(corePath)) if (!string_is_empty(core_path))
strlcpy(corePathCached, corePath, sizeof(corePathCached)); strlcpy(core_path_cached, core_path, sizeof(core_path_cached));
/* Add lpl extension to db_name, if required */ /* Add lpl extension to db_name, if required */
if (!string_is_empty(contentDbName)) if (!string_is_empty(content_db_name))
{ {
const char *extension = NULL; size_t _len = strlcpy(content_db_name_full, content_db_name,
sizeof(content_db_name_full));
const char *ext = path_get_extension(content_db_name_full);
strlcpy(contentDbNameFull, contentDbName, sizeof(contentDbNameFull)); if ( string_is_empty(ext)
extension = path_get_extension(contentDbNameFull); || !string_is_equal_noncase(ext,
FILE_PATH_LPL_EXTENSION_NO_DOT))
if ( string_is_empty(extension) strlcpy(
|| !string_is_equal_noncase( content_db_name_full + _len,
extension, FILE_PATH_LPL_EXTENSION_NO_DOT)) FILE_PATH_LPL_EXTENSION,
strlcat( sizeof(content_db_name_full) - _len);
contentDbNameFull, FILE_PATH_LPL_EXTENSION,
sizeof(contentDbNameFull));
} }
content_info.argc = 0; content_info.argc = 0;
@ -2861,7 +2861,11 @@ void MainWindow::loadContent(const QHash<QString, QString> &contentHash)
command_event(CMD_EVENT_UNLOAD_CORE, NULL); command_event(CMD_EVENT_UNLOAD_CORE, NULL);
if (!task_push_load_content_with_new_core_from_companion_ui( if (!task_push_load_content_with_new_core_from_companion_ui(
corePathCached, contentPath, contentLabel, contentDbNameFull, contentCrc32, core_path_cached,
content_path,
content_label,
content_db_name_full,
content_crc32,
&content_info, NULL, NULL)) &content_info, NULL, NULL))
{ {
QMessageBox::critical(this, msg_hash_to_str(MSG_ERROR), QMessageBox::critical(this, msg_hash_to_str(MSG_ERROR),