diff --git a/cheat_manager.c b/cheat_manager.c index d0d2e3ec054..18256e0c5e7 100644 --- a/cheat_manager.c +++ b/cheat_manager.c @@ -68,10 +68,10 @@ unsigned cheat_manager_get_size(void) #ifdef HAVE_CHEEVOS static void cheat_manager_pause_cheevos(void) { - const char *msg = msg_hash_to_str(MSG_CHEEVOS_HARDCORE_MODE_DISABLED_CHEAT); + char msg[128]; + size_t _len = strlcpy(msg, msg_hash_to_str(MSG_CHEEVOS_HARDCORE_MODE_DISABLED_CHEAT), sizeof(msg)); rcheevos_pause_hardcore(); - - runloop_msg_queue_push(msg, strlen(msg), 1, 180, true, NULL, + runloop_msg_queue_push(msg, _len, 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); RARCH_LOG("%s\n", msg); } @@ -106,10 +106,11 @@ void cheat_manager_apply_cheats(void) if (cheat_st->size > 0 && settings->bools.notification_show_cheats_applied) { - const char *_msg = msg_hash_to_str(MSG_APPLYING_CHEAT); - runloop_msg_queue_push(_msg, strlen(_msg), 1, 180, true, NULL, + char msg[128]; + size_t _len = strlcpy(msg, msg_hash_to_str(MSG_APPLYING_CHEAT), sizeof(msg)); + runloop_msg_queue_push(msg, _len, 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); - RARCH_LOG("%s\n", _msg); + RARCH_LOG("%s\n", msg); } #ifdef HAVE_CHEEVOS @@ -854,8 +855,9 @@ int cheat_manager_initialize_memory(rarch_setting_t *setting, size_t idx, bool w meminfo.id = RETRO_MEMORY_SYSTEM_RAM; if (!core_get_memory(&meminfo)) { - const char *_msg = msg_hash_to_str(MSG_CHEAT_INIT_FAIL); - runloop_msg_queue_push(_msg, strlen(_msg), 1, 180, true, NULL, + char msg[128]; + size_t _len = strlcpy(msg, msg_hash_to_str(MSG_CHEAT_INIT_FAIL), sizeof(msg)); + runloop_msg_queue_push(msg, _len, 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); return 0; } @@ -885,7 +887,6 @@ int cheat_manager_initialize_memory(rarch_setting_t *setting, size_t idx, bool w if (is_search_initialization) { - const char *msg = NULL; if (cheat_st->prev_memory_buf) { free(cheat_st->prev_memory_buf); @@ -897,8 +898,9 @@ int cheat_manager_initialize_memory(rarch_setting_t *setting, size_t idx, bool w if (!cheat_st->prev_memory_buf) { - const char *_msg = msg_hash_to_str(MSG_CHEAT_INIT_FAIL); - runloop_msg_queue_push(_msg, strlen(_msg), 1, 180, true, NULL, + char msg[128]; + size_t _len = strlcpy(msg, msg_hash_to_str(MSG_CHEAT_INIT_FAIL), sizeof(msg)); + runloop_msg_queue_push(msg, _len, 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); return 0; } @@ -914,10 +916,11 @@ int cheat_manager_initialize_memory(rarch_setting_t *setting, size_t idx, bool w if (!cheat_st->matches) { - const char *_msg = msg_hash_to_str(MSG_CHEAT_INIT_FAIL); + char msg[128]; + size_t _len = strlcpy(msg, msg_hash_to_str(MSG_CHEAT_INIT_FAIL), sizeof(msg)); free(cheat_st->prev_memory_buf); cheat_st->prev_memory_buf = NULL; - runloop_msg_queue_push(_msg, strlen(_msg), 1, 180, true, NULL, + runloop_msg_queue_push(msg, _len, 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); return 0; } @@ -934,9 +937,12 @@ int cheat_manager_initialize_memory(rarch_setting_t *setting, size_t idx, bool w offset += cheat_st->memory_size_list[i]; } - msg = msg_hash_to_str(MSG_CHEAT_INIT_SUCCESS); - runloop_msg_queue_push(msg, strlen(msg), 1, 180, true, NULL, - MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); + { + char msg[128]; + size_t _len = strlcpy(msg, msg_hash_to_str(MSG_CHEAT_INIT_SUCCESS), sizeof(msg)); + runloop_msg_queue_push(msg, _len, 1, 180, true, NULL, + MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); + } cheat_st->memory_search_initialized = true; } @@ -1034,8 +1040,8 @@ static int cheat_manager_search(enum cheat_search_type search_type) if (cheat_st->num_memory_buffers == 0 || !prev || !cheat_st->matches) { - const char *msg = msg_hash_to_str(MSG_CHEAT_SEARCH_NOT_INITIALIZED); - runloop_msg_queue_push(msg, strlen(msg), 1, 180, true, NULL, + _len = strlcpy(msg, msg_hash_to_str(MSG_CHEAT_SEARCH_NOT_INITIALIZED), sizeof(msg)); + runloop_msg_queue_push(msg, _len, 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); return 0; } @@ -1241,8 +1247,8 @@ int cheat_manager_add_matches(const char *path, if (cheat_st->num_matches + cheat_st->size > 100) { - const char *_msg = msg_hash_to_str(MSG_CHEAT_SEARCH_ADDED_MATCHES_TOO_MANY); - runloop_msg_queue_push(_msg, strlen(_msg), 1, 180, true, NULL, + _len = strlcpy(msg, msg_hash_to_str(MSG_CHEAT_SEARCH_ADDED_MATCHES_TOO_MANY), sizeof(msg)); + runloop_msg_queue_push(msg, _len, 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); return 0; } @@ -1281,8 +1287,8 @@ int cheat_manager_add_matches(const char *path, if (!cheat_manager_add_new_code(cheat_st->search_bit_size, idx, (mask << (byte_part * bits)), cheat_st->big_endian, curr_val)) { - const char *_msg = msg_hash_to_str(MSG_CHEAT_SEARCH_ADDED_MATCHES_FAIL); - runloop_msg_queue_push(_msg, strlen(_msg), 1, 180, true, NULL, + _len = strlcpy(msg, msg_hash_to_str(MSG_CHEAT_SEARCH_ADDED_MATCHES_FAIL), sizeof(msg)); + runloop_msg_queue_push(msg, _len, 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); return 0; } @@ -1296,8 +1302,8 @@ int cheat_manager_add_matches(const char *path, if (!cheat_manager_add_new_code(cheat_st->search_bit_size, idx, 0xFF, cheat_st->big_endian, curr_val)) { - const char *_msg = msg_hash_to_str(MSG_CHEAT_SEARCH_ADDED_MATCHES_FAIL); - runloop_msg_queue_push(_msg, strlen(_msg), 1, 180, true, NULL, + _len = strlcpy(msg, msg_hash_to_str(MSG_CHEAT_SEARCH_ADDED_MATCHES_FAIL), sizeof(msg)); + runloop_msg_queue_push(msg, _len, 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); return 0; } @@ -1638,30 +1644,30 @@ void cheat_manager_match_action(enum cheat_match_action_type match_action, unsig switch (bytes_per_item) { - case 2: - curr_val = cheat_st->big_endian ? + case 2: + curr_val = cheat_st->big_endian ? (*(curr + idx - offset) * 256) + *(curr + idx + 1 - offset) : *(curr + idx - offset) + (*(curr + idx + 1 - offset) * 256); - if (prev) - prev_val = cheat_st->big_endian ? + if (prev) + prev_val = cheat_st->big_endian ? (*(prev + idx) * 256) + *(prev + idx + 1) : *(prev + idx) + (*(prev + idx + 1) * 256); - break; - case 4: - curr_val = cheat_st->big_endian ? + break; + case 4: + curr_val = cheat_st->big_endian ? (*(curr + idx - offset) * 256 * 256 * 256) + (*(curr + idx + 1 - offset) * 256 * 256) + (*(curr + idx + 2 - offset) * 256) + *(curr + idx + 3 - offset) : *(curr + idx - offset) + (*(curr + idx + 1 - offset) * 256) + (*(curr + idx + 2 - offset) * 256 * 256) + (*(curr + idx + 3 - offset) * 256 * 256 * 256); - if (prev) - prev_val = cheat_st->big_endian ? + if (prev) + prev_val = cheat_st->big_endian ? (*(prev + idx) * 256 * 256 * 256) + (*(prev + idx + 1) * 256 * 256) + (*(prev + idx + 2) * 256) + *(prev + idx + 3) : *(prev + idx) + (*(prev + idx + 1) * 256) + (*(prev + idx + 2) * 256 * 256) + (*(prev + idx + 3) * 256 * 256 * 256); - break; - case 1: - default: - curr_val = *(curr + idx - offset); - if (prev) - prev_val = *(prev + idx); - break; + break; + case 1: + default: + curr_val = *(curr + idx - offset); + if (prev) + prev_val = *(prev + idx); + break; } if (match_action == CHEAT_MATCH_ACTION_TYPE_BROWSE) diff --git a/configuration.c b/configuration.c index 7eb6c08e1e2..6771ca4979b 100644 --- a/configuration.c +++ b/configuration.c @@ -4469,8 +4469,9 @@ bool config_load_override(void *data) if (settings->bools.notification_show_config_override_load && show_notification) { - const char *_msg = msg_hash_to_str(MSG_CONFIG_OVERRIDE_LOADED); - runloop_msg_queue_push(_msg, strlen(_msg), 1, 100, false, NULL, + char msg[128]; + size_t _len = strlcpy(msg, msg_hash_to_str(MSG_CONFIG_OVERRIDE_LOADED), sizeof(msg)); + runloop_msg_queue_push(msg, _len, 1, 100, false, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); } @@ -4525,8 +4526,9 @@ bool config_load_override_file(const char *config_path) if (settings->bools.notification_show_config_override_load && show_notification) { - const char *_msg = msg_hash_to_str(MSG_CONFIG_OVERRIDE_LOADED); - runloop_msg_queue_push(_msg, strlen(_msg), 1, 100, false, NULL, + char msg[128]; + size_t _len = strlcpy(msg, msg_hash_to_str(MSG_CONFIG_OVERRIDE_LOADED), sizeof(msg)); + runloop_msg_queue_push(msg, _len, 1, 100, false, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); } @@ -4735,8 +4737,9 @@ bool config_load_remap(const char *directory_input_remapping, success: if (notification_show_remap_load) { - const char *_msg = msg_hash_to_str(msg_remap_loaded); - runloop_msg_queue_push(_msg, strlen(_msg), 1, 100, false, NULL, + char _msg[128]; + size_t _len = strlcpy(_msg, msg_hash_to_str(msg_remap_loaded), sizeof(_msg)); + runloop_msg_queue_push(_msg, _len, 1, 100, false, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); } return true; diff --git a/disk_control_interface.c b/disk_control_interface.c index 225f4c97551..19ae7c5c5b9 100644 --- a/disk_control_interface.c +++ b/disk_control_interface.c @@ -273,58 +273,55 @@ void disk_control_get_image_label( * Generates an appropriate log/notification message * for a disk index change event **/ -static void disk_control_get_index_set_msg( +static size_t disk_control_get_index_set_msg( disk_control_interface_t *disk_control, unsigned num_images, unsigned index, bool success, - unsigned *msg_duration, char *msg, size_t len) + unsigned *msg_duration, char *s, size_t len) { - bool has_label = false; - char image_label[128]; - - image_label[0] = '\0'; - - if (!disk_control || !msg_duration || !msg || len < 1) - return; - - /* Attempt to get image label */ + size_t _len = 0; + if (!disk_control || !msg_duration || !s || len < 1) + return 0; + /* Check whether image was inserted or removed */ if (index < num_images) { + char image_label[128]; + bool has_label = false; + image_label[0] = '\0'; disk_control_get_image_label( disk_control, index, image_label, sizeof(image_label)); - has_label = !string_is_empty(image_label); - } - /* Get message duration - * > Default is 60 - * > If a label is shown, then increase duration by 50% - * > For errors, duration is always 180 */ - *msg_duration = success ? - (has_label ? 90 : 60) : - 180; + has_label = !string_is_empty(image_label); - /* Check whether image was inserted or removed */ - if (index < num_images) - { - size_t _len = strlcpy(msg, + /* Get message duration + * > Default is 60 + * > If a label is shown, then increase duration by 50% + * > For errors, duration is always 180 */ + *msg_duration = success ? (has_label ? 90 : 60) : 180; + + _len = strlcpy(s, success ? msg_hash_to_str(MSG_SETTING_DISK_IN_TRAY) : msg_hash_to_str(MSG_FAILED_TO_SET_DISK), len); if (has_label) - snprintf( - msg + _len, len - _len, ": %u/%u - %s", + _len += snprintf( + s + _len, len - _len, ": %u/%u - %s", index + 1, num_images, image_label); else - snprintf( - msg + _len, len - _len, ": %u/%u", + _len += snprintf( + s + _len, len - _len, ": %u/%u", index + 1, num_images); } else - strlcpy( - msg, + { + *msg_duration = success ? 60 : 180; + _len += strlcpy( + s, success ? msg_hash_to_str(MSG_REMOVED_DISK_FROM_TRAY) : msg_hash_to_str(MSG_FAILED_TO_REMOVE_DISK_FROM_TRAY), len); + } + return _len; } /** @@ -404,6 +401,7 @@ bool disk_control_set_index( disk_control_interface_t *disk_control, unsigned index, bool verbosity) { + size_t _len; bool error = false; unsigned num_images = 0; unsigned msg_duration = 0; @@ -430,12 +428,12 @@ bool disk_control_set_index( error = !disk_control->cb.set_image_index(index); /* Get log/notification message */ - disk_control_get_index_set_msg( + _len = disk_control_get_index_set_msg( disk_control, num_images, index, !error, &msg_duration, msg, sizeof(msg)); /* Output log/notification message */ - if (!string_is_empty(msg)) + if (_len > 0) { if (error) RARCH_ERR("[Disc]: %s\n", msg); @@ -444,7 +442,7 @@ bool disk_control_set_index( /* Errors should always be displayed */ if (verbosity || error) - runloop_msg_queue_push(msg, strlen(msg), 1, msg_duration, true, NULL, + runloop_msg_queue_push(msg, _len, 1, msg_duration, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); } @@ -799,7 +797,10 @@ bool disk_control_verify_initial_index( /* If current disk is incorrect, notify user */ if (!success && enabled) { - const char *_msg = msg_hash_to_str(MSG_FAILED_TO_SET_INITIAL_DISK); + char _msg[128]; + size_t _len = strlcpy(_msg, + msg_hash_to_str(MSG_FAILED_TO_SET_INITIAL_DISK), sizeof(_msg)); + RARCH_ERR( "[Disc]: Failed to set initial disc index:\n> Expected" " [%u] %s\n> Detected [%u] %s\n", @@ -810,7 +811,7 @@ bool disk_control_verify_initial_index( /* Ignore 'verbosity' setting - errors should * always be displayed */ - runloop_msg_queue_push(_msg, strlen(_msg), 0, 60, true, NULL, + runloop_msg_queue_push(_msg, _len, 0, 60, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); /* Since a failure here typically means that the @@ -835,12 +836,13 @@ bool disk_control_verify_initial_index( * is available */ if (disk_control->initial_num_images > 1) { + size_t _len; unsigned msg_duration = 0; char msg[128]; msg[0] = '\0'; - disk_control_get_index_set_msg( + _len = disk_control_get_index_set_msg( disk_control, disk_control->initial_num_images, image_index, true, &msg_duration, msg, sizeof(msg)); @@ -852,7 +854,7 @@ bool disk_control_verify_initial_index( * we do not want to 'overwrite' them */ if (verbosity) runloop_msg_queue_push( - msg, strlen(msg), 0, msg_duration, false, NULL, + msg, _len, 0, msg_duration, false, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); #ifdef HAVE_CHEEVOS diff --git a/gfx/gfx_widgets.c b/gfx/gfx_widgets.c index f6f9e06f4d0..6024d958ece 100644 --- a/gfx/gfx_widgets.c +++ b/gfx/gfx_widgets.c @@ -1123,12 +1123,13 @@ static int gfx_widgets_draw_indicator( } else { + char txt[NAME_MAX_LENGTH]; unsigned height = p_dispwidget->simple_widget_height; - const char *txt = msg_hash_to_str(msg); + size_t _len = strlcpy(txt, msg_hash_to_str(msg), sizeof(txt)); width = font_driver_get_message_width( p_dispwidget->gfx_widget_fonts.regular.font, - txt, strlen(txt), 1.0f) + txt, _len, 1.0f) + p_dispwidget->simple_widget_padding * 2; gfx_display_draw_quad(