[PATCH v2 1/2] bootmenu: use utf-8 for menu title

Pali Rohar pali at kernel.org
Sun May 29 11:07:18 CEST 2022


On Sunday 29 May 2022 10:37:23 Masahisa Kojima wrote:
> On Sat, 28 May 2022 at 17:37, Heinrich Schuchardt <xypron.glpk at gmx.de> wrote:
> > On 5/26/22 12:09, Masahisa Kojima wrote:
> > > @@ -183,13 +183,13 @@ static int prepare_bootmenu_entry(struct bootmenu_data *menu,
> > >                       return -ENOMEM;
> > >
> > >               len = sep-option;
> >
> > %s/sep-option/sep - option/
> 
> OK.
> 
> >
> > > -             buf = calloc(1, (len + 1) * sizeof(u16));
> > > +             buf = calloc(1, (len + 1));
> > >               entry->title = buf;
> > >               if (!entry->title) {
> > >                       free(entry);
> > >                       return -ENOMEM;
> > >               }
> > > -             utf8_utf16_strncpy(&buf, option, len);
> > > +             strncpy(buf, option, len);
> >
> > Instead of two function calls (calloc, strncpy) simply use strdup().
> 
> bootmenu_x format is "[title]=[commands]", title is not the
> NUL-terminated string, so we can not use strdup here.

Usage of C's strncpy() function should be in most cases avoided as when
target buffer does not have enough space this function does not fill
nul-term byte. (Anyway, I do not know if U-Boot implements strncpy()
according to C standard with this trap or not)

But if you already have length of string then you should use memcpy().

> >
> > >
> > >               len = strlen(sep + 1);
> > >               entry->command = malloc(len + 1);
> >
> > Use strdup() here too.
> 
> OK, command is NUL-terminated.
> 
> Thank you for your comment.
> 
> Regards,
> Masahisa Kojima


More information about the U-Boot mailing list