mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
Callers of cp_to_unicode() assert that it didn't return UCS_NO_CHAR.
UCS_NO_CHAR here means the input was too short. Because the strings generally come from the source code or from PO files, they should not end in the middle of a character. However, the whole character may be missing if the string is empty. So select_button_by_key() now checks for that case separately. UCS_NO_CHAR must not be passed to unicode_fold_label_case() because the result is undefined.
This commit is contained in:
parent
388b1b0efd
commit
677e5c7adc
@ -310,18 +310,24 @@ select_button_by_key(struct dialog_data *dlg_data)
|
||||
if (widget_data->widget->type != WIDGET_BUTTON)
|
||||
continue;
|
||||
|
||||
hk_ptr = widget_data->widget->text;
|
||||
if (!*hk_ptr)
|
||||
continue;
|
||||
|
||||
/* We first try to match marked hotkey if there is
|
||||
* one else we fallback to first character in button
|
||||
* name. */
|
||||
hk_pos = widget_data->widget->info.button.hotkey_pos;
|
||||
if (hk_pos >= 0)
|
||||
hk_ptr = &widget_data->widget->text[hk_pos + 1];
|
||||
else
|
||||
hk_ptr = widget_data->widget->text;
|
||||
hk_ptr += hk_pos + 1;
|
||||
|
||||
#ifdef CONFIG_UTF8
|
||||
hk_char = cp_to_unicode(codepage, &hk_ptr,
|
||||
strchr(hk_ptr, '\0'));
|
||||
/* hk_char can be UCS_NO_CHAR only if the text of the
|
||||
* widget is not in the expected codepage. */
|
||||
assert(hk_char != UCS_NO_CHAR);
|
||||
if_assert_failed continue;
|
||||
hk_char = unicode_fold_label_case(hk_char);
|
||||
#else
|
||||
hk_char = toupper(*hk_ptr);
|
||||
|
@ -179,6 +179,10 @@ check_hotkeys_common(struct menu *menu, term_event_char_T hotkey, struct termina
|
||||
#ifdef CONFIG_UTF8
|
||||
items_hotkey = cp_to_unicode(codepage, &text,
|
||||
strchr(text, '\0'));
|
||||
/* items_hotkey can be UCS_NO_CHAR only if the text of
|
||||
* the menu item is not in the expected codepage. */
|
||||
assert(items_hotkey != UCS_NO_CHAR);
|
||||
if_assert_failed continue;
|
||||
found = (unicode_fold_label_case(items_hotkey) == key);
|
||||
#else
|
||||
found = (toupper(*text) == key);
|
||||
|
Loading…
x
Reference in New Issue
Block a user