From 25b76fdb5453ad60a14a1194d5ecc3f604ef3b74 Mon Sep 17 00:00:00 2001 From: LibretroAdmin Date: Sat, 27 Aug 2022 15:13:56 +0200 Subject: [PATCH] input_keyboard_osk_event_append and others: don't call strlen implicitly, always leave it up to caller font_driver_get_message_width - try to avoid scenario where 'len' is 0 --- gfx/gfx_widgets.c | 12 +++++++----- gfx/widgets/gfx_widget_achievement_popup.c | 13 ++++++++----- input/input_driver.c | 8 ++++---- input/input_driver.h | 2 +- input/input_osk.h | 3 ++- menu/drivers/materialui.c | 6 +++--- menu/drivers/ozone.c | 6 +++--- menu/menu_driver.c | 11 ++++++----- 8 files changed, 34 insertions(+), 27 deletions(-) diff --git a/gfx/gfx_widgets.c b/gfx/gfx_widgets.c index 2e17a0a7e8..96db5a3fc1 100644 --- a/gfx/gfx_widgets.c +++ b/gfx/gfx_widgets.c @@ -274,7 +274,7 @@ void gfx_widgets_msg_queue_push( msg_widget->width = font_driver_get_message_width( p_dispwidget->gfx_widget_fonts.msg_queue.font, title, - msg_widget->msg_len, 1) + + msg_widget->msg_len, 1.0f) + p_dispwidget->simple_widget_padding / 2; task->frontend_userdata = msg_widget; @@ -296,7 +296,7 @@ void gfx_widgets_msg_queue_push( p_dispwidget->gfx_widget_fonts.msg_queue.font, title, title_length, - 1); + 1.0f); msg_widget->text_height = p_dispwidget->gfx_widget_fonts.msg_queue.line_height; /* 1 byte uses for inserting '\n' */ msg_len = title_length + 1 + 1; @@ -361,7 +361,7 @@ void gfx_widgets_msg_queue_push( p_dispwidget->gfx_widget_fonts.msg_queue.font, title, len, - 1); + 1.0f); msg_widget->msg_len = len; msg_widget->msg_transition_animation = 0; @@ -1107,9 +1107,11 @@ static int gfx_widgets_draw_indicator( unsigned height = p_dispwidget->simple_widget_height; const char *txt = msg_hash_to_str(msg); - width = font_driver_get_message_width(p_dispwidget->gfx_widget_fonts.regular.font, + width = font_driver_get_message_width( + p_dispwidget->gfx_widget_fonts.regular.font, txt, - (unsigned)strlen(txt), 1) + p_dispwidget->simple_widget_padding * 2; + (unsigned)strlen(txt), 1.0f) + + p_dispwidget->simple_widget_padding * 2; gfx_display_draw_quad( p_disp, diff --git a/gfx/widgets/gfx_widget_achievement_popup.c b/gfx/widgets/gfx_widget_achievement_popup.c index eccea856f4..6faaea49fd 100644 --- a/gfx/widgets/gfx_widget_achievement_popup.c +++ b/gfx/widgets/gfx_widget_achievement_popup.c @@ -385,15 +385,18 @@ static void gfx_widget_achievement_popup_start( gfx_animation_ctx_entry_t entry; const dispgfx_widget_t *p_dispwidget = (const dispgfx_widget_t*) state->dispwidget_ptr; - - state->height = p_dispwidget->gfx_widget_fonts.regular.line_height * 4; - state->width = MAX( + size_t title_len = strlen(state->queue[state->queue_read_index].title); + size_t stitle_len = strlen(state->queue[state->queue_read_index].subtitle); + state->height = p_dispwidget->gfx_widget_fonts.regular.line_height * 4; + state->width = MAX( font_driver_get_message_width( p_dispwidget->gfx_widget_fonts.regular.font, - state->queue[state->queue_read_index].title, 0, 1), + state->queue[state->queue_read_index].title, title_len, + 1.0f), font_driver_get_message_width( p_dispwidget->gfx_widget_fonts.regular.font, - state->queue[state->queue_read_index].subtitle, 0, 1) + state->queue[state->queue_read_index].subtitle, stitle_len, + 1.0f) ); state->width += p_dispwidget->simple_widget_padding * 2; state->y = (float)(-(int)state->height); diff --git a/input/input_driver.c b/input/input_driver.c index c31e6cd77a..c94d753e4d 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -975,10 +975,9 @@ int16_t input_joypad_analog_axis( void input_keyboard_line_append( struct input_keyboard_line *keyboard_line, - const char *word) + const char *word, size_t len) { int i; - size_t len = strlen(word); char *newbuf = (char*)realloc( keyboard_line->buffer, keyboard_line->size + len * 2); @@ -2356,7 +2355,8 @@ void input_event_osk_append( unsigned *osk_last_codepoint_len, int ptr, bool show_symbol_pages, - const char *word) + const char *word, + size_t word_len) { #ifdef HAVE_LANGEXTRA if (string_is_equal(word, "\xe2\x87\xa6")) /* backspace character */ @@ -2387,7 +2387,7 @@ void input_event_osk_append( *osk_idx = ((enum osk_type)(OSK_TYPE_UNKNOWN + 1)); else { - input_keyboard_line_append(keyboard_line, word); + input_keyboard_line_append(keyboard_line, word, word_len); osk_update_last_codepoint( osk_last_codepoint, osk_last_codepoint_len, diff --git a/input/input_driver.h b/input/input_driver.h index cde9d6e511..9133350ddb 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -909,7 +909,7 @@ int16_t input_joypad_analog_axis( void input_keyboard_line_append( struct input_keyboard_line *keyboard_line, - const char *word); + const char *word, size_t len); /** * input_keyboard_start_line: diff --git a/input/input_osk.h b/input/input_osk.h index 717276a7ad..fda6060a4d 100644 --- a/input/input_osk.h +++ b/input/input_osk.h @@ -54,7 +54,8 @@ void input_event_osk_append( unsigned *osk_last_codepoint_len, int ptr, bool show_symbol_pages, - const char *word); + const char *word, + size_t word_len); void osk_update_last_codepoint( unsigned *last_codepoint, diff --git a/menu/drivers/materialui.c b/menu/drivers/materialui.c index 815030e16c..c8c3e3aab5 100644 --- a/menu/drivers/materialui.c +++ b/menu/drivers/materialui.c @@ -2665,7 +2665,7 @@ static void materialui_render_messagebox( if (!string_is_empty(line)) { int width = font_driver_get_message_width( - mui->font_data.list.font, line, (unsigned)strlen(line), 1); + mui->font_data.list.font, line, (unsigned)strlen(line), 1.0f); longest_width = (width > longest_width) ? width : longest_width; } @@ -7789,7 +7789,7 @@ static void materialui_init_font( { /* Calculate a more realistic ticker_limit */ int char_width = - font_driver_get_message_width(font_data->font, str_latin, 1, 1); + font_driver_get_message_width(font_data->font, str_latin, 1, 1.0f); if (char_width > 0) font_data->glyph_width = (unsigned)char_width; @@ -7799,7 +7799,7 @@ static void materialui_init_font( if (wideglyph_str) { int wideglyph_width = - font_driver_get_message_width(font_data->font, wideglyph_str, (unsigned)strlen(wideglyph_str), 1); + font_driver_get_message_width(font_data->font, wideglyph_str, (unsigned)strlen(wideglyph_str), 1.0f); if (wideglyph_width > 0 && char_width > 0) font_data->wideglyph_width = wideglyph_width * 100 / char_width; diff --git a/menu/drivers/ozone.c b/menu/drivers/ozone.c index 716ff384b7..a3cabcd68b 100644 --- a/menu/drivers/ozone.c +++ b/menu/drivers/ozone.c @@ -5351,7 +5351,7 @@ border_iterate: { /* Note: This entry can never be selected, so ticker_x_offset * is irrelevant here (i.e. this text will never scroll) */ - unsigned text_width = font_driver_get_message_width(ozone->fonts.entries_label.font, rich_label, (unsigned)strlen(rich_label), 1); + unsigned text_width = font_driver_get_message_width(ozone->fonts.entries_label.font, rich_label, (unsigned)strlen(rich_label), 1.0f); x_offset = (video_info_width - (unsigned) ozone->dimensions_sidebar_width - entry_padding * 2) / 2 - text_width / 2 - 60 * scale_factor; @@ -6342,7 +6342,7 @@ static void ozone_draw_osk(ozone_handle_t *ozone, ? 0 : font_driver_get_message_width( ozone->fonts.entries_label.font, msg, - (unsigned)strlen(msg), 1); + (unsigned)strlen(msg), 1.0f); gfx_display_draw_quad( p_disp, userdata, @@ -6454,7 +6454,7 @@ static void ozone_draw_messagebox( if (!string_is_empty(msg)) { int width = font_driver_get_message_width( - ozone->fonts.footer.font, msg, (unsigned)strlen(msg), 1); + ozone->fonts.footer.font, msg, (unsigned)strlen(msg), 1.0f); if (width > longest_width) longest_width = width; diff --git a/menu/menu_driver.c b/menu/menu_driver.c index 7c7ee29511..6c26346136 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -5640,7 +5640,7 @@ bool menu_input_dialog_get_display_kb(void) char oldchar = buf[i+1]; buf[i+1] = '\0'; - input_keyboard_line_append(&input_st->keyboard_line, word); + input_keyboard_line_append(&input_st->keyboard_line, word, strlen(word)); osk_update_last_codepoint( &input_st->osk_last_codepoint, @@ -5978,7 +5978,8 @@ unsigned menu_event( &input_st->osk_last_codepoint_len, input_st->osk_ptr, show_osk_symbols, - input_st->osk_grid[input_st->osk_ptr]); + input_st->osk_grid[input_st->osk_ptr], + strlen(input_st->osk_grid[input_st->osk_ptr])); } if (BIT256_GET_PTR(p_trigger_input, menu_cancel_btn)) @@ -6400,8 +6401,7 @@ static int menu_input_pointer_post_iterate( if (point.retcode > -1) { bool show_osk_symbols = input_event_osk_show_symbol_pages(menu_st->driver_data); - - input_st->osk_ptr = point.retcode; + input_st->osk_ptr = point.retcode; input_event_osk_append( &input_st->keyboard_line, &input_st->osk_idx, @@ -6409,7 +6409,8 @@ static int menu_input_pointer_post_iterate( &input_st->osk_last_codepoint_len, point.retcode, show_osk_symbols, - input_st->osk_grid[input_st->osk_ptr]); + input_st->osk_grid[input_st->osk_ptr], + strlen(input_st->osk_grid[input_st->osk_ptr])); } } #ifdef HAVE_MIST