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
This commit is contained in:
LibretroAdmin 2022-08-27 15:13:56 +02:00
parent f34f4d060c
commit 25b76fdb54
8 changed files with 34 additions and 27 deletions

View File

@ -274,7 +274,7 @@ void gfx_widgets_msg_queue_push(
msg_widget->width = font_driver_get_message_width( msg_widget->width = font_driver_get_message_width(
p_dispwidget->gfx_widget_fonts.msg_queue.font, p_dispwidget->gfx_widget_fonts.msg_queue.font,
title, title,
msg_widget->msg_len, 1) + msg_widget->msg_len, 1.0f) +
p_dispwidget->simple_widget_padding / 2; p_dispwidget->simple_widget_padding / 2;
task->frontend_userdata = msg_widget; task->frontend_userdata = msg_widget;
@ -296,7 +296,7 @@ void gfx_widgets_msg_queue_push(
p_dispwidget->gfx_widget_fonts.msg_queue.font, p_dispwidget->gfx_widget_fonts.msg_queue.font,
title, title,
title_length, title_length,
1); 1.0f);
msg_widget->text_height = p_dispwidget->gfx_widget_fonts.msg_queue.line_height; msg_widget->text_height = p_dispwidget->gfx_widget_fonts.msg_queue.line_height;
/* 1 byte uses for inserting '\n' */ /* 1 byte uses for inserting '\n' */
msg_len = title_length + 1 + 1; msg_len = title_length + 1 + 1;
@ -361,7 +361,7 @@ void gfx_widgets_msg_queue_push(
p_dispwidget->gfx_widget_fonts.msg_queue.font, p_dispwidget->gfx_widget_fonts.msg_queue.font,
title, title,
len, len,
1); 1.0f);
msg_widget->msg_len = len; msg_widget->msg_len = len;
msg_widget->msg_transition_animation = 0; msg_widget->msg_transition_animation = 0;
@ -1107,9 +1107,11 @@ static int gfx_widgets_draw_indicator(
unsigned height = p_dispwidget->simple_widget_height; unsigned height = p_dispwidget->simple_widget_height;
const char *txt = msg_hash_to_str(msg); 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, 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( gfx_display_draw_quad(
p_disp, p_disp,

View File

@ -385,15 +385,18 @@ static void gfx_widget_achievement_popup_start(
gfx_animation_ctx_entry_t entry; gfx_animation_ctx_entry_t entry;
const dispgfx_widget_t *p_dispwidget = (const dispgfx_widget_t*) const dispgfx_widget_t *p_dispwidget = (const dispgfx_widget_t*)
state->dispwidget_ptr; state->dispwidget_ptr;
size_t title_len = strlen(state->queue[state->queue_read_index].title);
state->height = p_dispwidget->gfx_widget_fonts.regular.line_height * 4; size_t stitle_len = strlen(state->queue[state->queue_read_index].subtitle);
state->width = MAX( state->height = p_dispwidget->gfx_widget_fonts.regular.line_height * 4;
state->width = MAX(
font_driver_get_message_width( font_driver_get_message_width(
p_dispwidget->gfx_widget_fonts.regular.font, 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( font_driver_get_message_width(
p_dispwidget->gfx_widget_fonts.regular.font, 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->width += p_dispwidget->simple_widget_padding * 2;
state->y = (float)(-(int)state->height); state->y = (float)(-(int)state->height);

View File

@ -975,10 +975,9 @@ int16_t input_joypad_analog_axis(
void input_keyboard_line_append( void input_keyboard_line_append(
struct input_keyboard_line *keyboard_line, struct input_keyboard_line *keyboard_line,
const char *word) const char *word, size_t len)
{ {
int i; int i;
size_t len = strlen(word);
char *newbuf = (char*)realloc( char *newbuf = (char*)realloc(
keyboard_line->buffer, keyboard_line->buffer,
keyboard_line->size + len * 2); keyboard_line->size + len * 2);
@ -2356,7 +2355,8 @@ void input_event_osk_append(
unsigned *osk_last_codepoint_len, unsigned *osk_last_codepoint_len,
int ptr, int ptr,
bool show_symbol_pages, bool show_symbol_pages,
const char *word) const char *word,
size_t word_len)
{ {
#ifdef HAVE_LANGEXTRA #ifdef HAVE_LANGEXTRA
if (string_is_equal(word, "\xe2\x87\xa6")) /* backspace character */ 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)); *osk_idx = ((enum osk_type)(OSK_TYPE_UNKNOWN + 1));
else else
{ {
input_keyboard_line_append(keyboard_line, word); input_keyboard_line_append(keyboard_line, word, word_len);
osk_update_last_codepoint( osk_update_last_codepoint(
osk_last_codepoint, osk_last_codepoint,
osk_last_codepoint_len, osk_last_codepoint_len,

View File

@ -909,7 +909,7 @@ int16_t input_joypad_analog_axis(
void input_keyboard_line_append( void input_keyboard_line_append(
struct input_keyboard_line *keyboard_line, struct input_keyboard_line *keyboard_line,
const char *word); const char *word, size_t len);
/** /**
* input_keyboard_start_line: * input_keyboard_start_line:

View File

@ -54,7 +54,8 @@ void input_event_osk_append(
unsigned *osk_last_codepoint_len, unsigned *osk_last_codepoint_len,
int ptr, int ptr,
bool show_symbol_pages, bool show_symbol_pages,
const char *word); const char *word,
size_t word_len);
void osk_update_last_codepoint( void osk_update_last_codepoint(
unsigned *last_codepoint, unsigned *last_codepoint,

View File

@ -2665,7 +2665,7 @@ static void materialui_render_messagebox(
if (!string_is_empty(line)) if (!string_is_empty(line))
{ {
int width = font_driver_get_message_width( 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) ? longest_width = (width > longest_width) ?
width : longest_width; width : longest_width;
} }
@ -7789,7 +7789,7 @@ static void materialui_init_font(
{ {
/* Calculate a more realistic ticker_limit */ /* Calculate a more realistic ticker_limit */
int char_width = 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) if (char_width > 0)
font_data->glyph_width = (unsigned)char_width; font_data->glyph_width = (unsigned)char_width;
@ -7799,7 +7799,7 @@ static void materialui_init_font(
if (wideglyph_str) if (wideglyph_str)
{ {
int wideglyph_width = 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) if (wideglyph_width > 0 && char_width > 0)
font_data->wideglyph_width = wideglyph_width * 100 / char_width; font_data->wideglyph_width = wideglyph_width * 100 / char_width;

View File

@ -5351,7 +5351,7 @@ border_iterate:
{ {
/* Note: This entry can never be selected, so ticker_x_offset /* Note: This entry can never be selected, so ticker_x_offset
* is irrelevant here (i.e. this text will never scroll) */ * 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) x_offset = (video_info_width - (unsigned)
ozone->dimensions_sidebar_width - entry_padding * 2) ozone->dimensions_sidebar_width - entry_padding * 2)
/ 2 - text_width / 2 - 60 * scale_factor; / 2 - text_width / 2 - 60 * scale_factor;
@ -6342,7 +6342,7 @@ static void ozone_draw_osk(ozone_handle_t *ozone,
? 0 ? 0
: font_driver_get_message_width( : font_driver_get_message_width(
ozone->fonts.entries_label.font, msg, ozone->fonts.entries_label.font, msg,
(unsigned)strlen(msg), 1); (unsigned)strlen(msg), 1.0f);
gfx_display_draw_quad( gfx_display_draw_quad(
p_disp, p_disp,
userdata, userdata,
@ -6454,7 +6454,7 @@ static void ozone_draw_messagebox(
if (!string_is_empty(msg)) if (!string_is_empty(msg))
{ {
int width = font_driver_get_message_width( 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) if (width > longest_width)
longest_width = width; longest_width = width;

View File

@ -5640,7 +5640,7 @@ bool menu_input_dialog_get_display_kb(void)
char oldchar = buf[i+1]; char oldchar = buf[i+1];
buf[i+1] = '\0'; 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( osk_update_last_codepoint(
&input_st->osk_last_codepoint, &input_st->osk_last_codepoint,
@ -5978,7 +5978,8 @@ unsigned menu_event(
&input_st->osk_last_codepoint_len, &input_st->osk_last_codepoint_len,
input_st->osk_ptr, input_st->osk_ptr,
show_osk_symbols, 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)) 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) if (point.retcode > -1)
{ {
bool show_osk_symbols = input_event_osk_show_symbol_pages(menu_st->driver_data); 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_event_osk_append(
&input_st->keyboard_line, &input_st->keyboard_line,
&input_st->osk_idx, &input_st->osk_idx,
@ -6409,7 +6409,8 @@ static int menu_input_pointer_post_iterate(
&input_st->osk_last_codepoint_len, &input_st->osk_last_codepoint_len,
point.retcode, point.retcode,
show_osk_symbols, 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 #ifdef HAVE_MIST