If we are unable to correctly parse wide-character strings for display
in the Language screen (eg. due to an incorrect locale) display an
error string instead of continuing to try to display the string.
Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
#include <talloc/talloc.h>
#include <types/types.h>
#include <talloc/talloc.h>
#include <types/types.h>
len = wcstombs(NULL, lang->label, 0);
assert(len >= 0);
len = wcstombs(NULL, lang->label, 0);
assert(len >= 0);
- label = talloc_array(screen, char, len + 1);
- wcstombs(label, lang->label, len + 1);
+ if (len < 0) {
+ label = talloc_asprintf(screen,
+ "Unable to display text in this locale (%s)\n",
+ setlocale(LC_ALL, NULL));
+ } else {
+ label = talloc_array(screen, char, len + 1);
+ wcstombs(label, lang->label, len + 1);
+ }
selected = config->lang && !strcmp(lang->name, config->lang);
found |= selected;
selected = config->lang && !strcmp(lang->name, config->lang);
found |= selected;