1
0
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:
Kalle Olavi Niemitalo 2006-09-17 19:54:37 +03:00 committed by Kalle Olavi Niemitalo
parent 388b1b0efd
commit 677e5c7adc
2 changed files with 13 additions and 3 deletions

View File

@ -310,18 +310,24 @@ select_button_by_key(struct dialog_data *dlg_data)
if (widget_data->widget->type != WIDGET_BUTTON) if (widget_data->widget->type != WIDGET_BUTTON)
continue; continue;
hk_ptr = widget_data->widget->text;
if (!*hk_ptr)
continue;
/* We first try to match marked hotkey if there is /* We first try to match marked hotkey if there is
* one else we fallback to first character in button * one else we fallback to first character in button
* name. */ * name. */
hk_pos = widget_data->widget->info.button.hotkey_pos; hk_pos = widget_data->widget->info.button.hotkey_pos;
if (hk_pos >= 0) if (hk_pos >= 0)
hk_ptr = &widget_data->widget->text[hk_pos + 1]; hk_ptr += hk_pos + 1;
else
hk_ptr = widget_data->widget->text;
#ifdef CONFIG_UTF8 #ifdef CONFIG_UTF8
hk_char = cp_to_unicode(codepage, &hk_ptr, hk_char = cp_to_unicode(codepage, &hk_ptr,
strchr(hk_ptr, '\0')); 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); hk_char = unicode_fold_label_case(hk_char);
#else #else
hk_char = toupper(*hk_ptr); hk_char = toupper(*hk_ptr);

View File

@ -179,6 +179,10 @@ check_hotkeys_common(struct menu *menu, term_event_char_T hotkey, struct termina
#ifdef CONFIG_UTF8 #ifdef CONFIG_UTF8
items_hotkey = cp_to_unicode(codepage, &text, items_hotkey = cp_to_unicode(codepage, &text,
strchr(text, '\0')); 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); found = (unicode_fold_label_case(items_hotkey) == key);
#else #else
found = (toupper(*text) == key); found = (toupper(*text) == key);