[PATCH 2/3] lib/charset: add u16_strcat() function

Masahisa Kojima masahisa.kojima at linaro.org
Mon Feb 14 02:51:12 CET 2022


Hi Heinrich,

On Sun, 13 Feb 2022 at 19:12, Heinrich Schuchardt <xypron.glpk at gmx.de> wrote:
>
> On 2/10/22 08:05, Masahisa Kojima wrote:
> > Provide u16 string version of strcat().
> >
> > Signed-off-by: Masahisa Kojima <masahisa.kojima at linaro.org>
>
> Please, provide a test in test/unicode_ut.c.

Yes, I will add.

> > ---
> >   include/charset.h | 13 +++++++++++++
> >   lib/charset.c     | 12 ++++++++++++
> >   2 files changed, 25 insertions(+)
> >
> > diff --git a/include/charset.h b/include/charset.h
> > index b93d023092..baba9d7c14 100644
> > --- a/include/charset.h
> > +++ b/include/charset.h
> > @@ -259,6 +259,19 @@ u16 *u16_strcpy(u16 *dest, const u16 *src);
> >    */
> >   u16 *u16_strdup(const void *src);
> >
> > +/**
> > + * u16_strcat() - append u16 string
> > + *
> > + * Append the src string to the dest string, overwriting the terminating
> > + * null word at the end of dest, and then adds a terminating null word.
> > + * The dest string must have enough space for the result.
> > + *
> > + * @dest:            destination buffer (null terminated)
> > + * @src:             source buffer (null terminated)
> > + * Return:           'dest' address
> > + */
> > +u16 *u16_strcat(u16 *dest, const u16 *src);
>
> This is unsafe. Please, provide an argument for the destination buffer
> size. If you still need a version without the argument, simply use a
> define like we did for other functions.

OK, I will create u16_strcat_s() instead of u16_strcat().

Thank you for your review.

Regards,
Masahisa Kojima

>
> Best regards
>
> Heinrich
>
> > +
> >   /**
> >    * utf16_to_utf8() - Convert an utf16 string to utf8
> >    *
> > diff --git a/lib/charset.c b/lib/charset.c
> > index f44c58d9d8..f0eaf6c1ae 100644
> > --- a/lib/charset.c
> > +++ b/lib/charset.c
> > @@ -428,6 +428,18 @@ u16 *u16_strdup(const void *src)
> >       return new;
> >   }
> >
> > +u16 *u16_strcat(u16 *dest, const u16 *src)
> > +{
> > +     u16 *tmp = dest;
> > +
> > +     while (*dest)
> > +             dest++;
> > +     while ((*dest++ = *src++) != u'\0')
> > +             ;
> > +
> > +     return tmp;
> > +}
> > +
> >   /* Convert UTF-16 to UTF-8.  */
> >   uint8_t *utf16_to_utf8(uint8_t *dest, const uint16_t *src, size_t size)
> >   {
>


More information about the U-Boot mailing list