]> git.ozlabs.org Git - petitboot/blobdiff - ui/ncurses/nc-lang.c
ui/ncurses: Check wcstombs() for error in nc-lang
[petitboot] / ui / ncurses / nc-lang.c
index 7879c457cfe9eb8daa877f56cbd51f8e87df63d0..a7c9ccc53bb53f24b755a2d2c3109752dc4da05e 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <locale.h>
 
 #include <talloc/talloc.h>
 #include <types/types.h>
@@ -265,8 +266,14 @@ static void lang_screen_setup_widgets(struct lang_screen *screen,
 
                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;