On Mon, May 28, 2018 at 01:21:15PM +0200, Claudius Heine wrote:
> Hi,
> 
> On 2018-05-25 14:00, [ext] Andreas J. Reichel wrote:
> > From: Andreas Reichel <[email protected]>
> > 
> > To compare device paths it is necessary to be able to split of
> > sub-paths from the right hand side. Implement a simple function
> > for that purpose.
> > 
> > Signed-off-by: Andreas Reichel <[email protected]>
> > ---
> >   include/utils.h |  1 +
> >   utils.c         | 23 +++++++++++++++++++++++
> >   2 files changed, 24 insertions(+)
> > 
> > diff --git a/include/utils.h b/include/utils.h
> > index 285e45e..06721eb 100644
> > --- a/include/utils.h
> > +++ b/include/utils.h
> > @@ -29,6 +29,7 @@ typedef struct _VOLUME_DESC {
> >   typedef enum { DOSFSLABEL, CUSTOMLABEL, NOLABEL } LABELMODE;
> > +CHAR16 *StrRStrip(CHAR16 *input, CHAR16 delim);
> >   uint32_t calc_crc32(void *data, int32_t size);
> >   void __noreturn error_exit(CHAR16 *message, EFI_STATUS status);
> >   VOID sleep(int32_t sec);
> > diff --git a/utils.c b/utils.c
> > index 33e3a90..4f44a37 100644
> > --- a/utils.c
> > +++ b/utils.c
> > @@ -16,6 +16,29 @@
> >   #include <bootguard.h>
> >   #include <utils.h>
> > +CHAR16 *StrRStrip(CHAR16 *input, CHAR16 delim)
> > +{
> > +   CHAR16 *dst;
> > +   UINTN len;
> > +
> > +   len = StrLen(input);
> > +   dst = mmalloc((len + 1) * 2);
> 
> Magic numbers. Use 'sizeof'.
> 

okay...

> > +   if (!dst) {
> > +           return NULL;
> > +   }
> > +
> > +   StrCpy(dst, input);
> > +
> > +   for (UINTN i = len; i > 0; i--)
> > +   {
> > +           if (dst[i * 2] == delim) {
> > +                   dst[i * 2] = L'\0';
> > +                   break;
> > +           }
> > +   }
> 
> Here I get this itching in my coding fingers. I would try do copying and
> striping in one loop.
> 

As discussed, I used predefined functions and we had different ideas
about what a 'RStrip' function should do. Changing the name to make
clear that this is a function of special intent for device paths is
better.

> Claudius
> 
> > +   return dst;
> > +}
> > +
> >   uint32_t calc_crc32(void *data, int32_t size)
> >   {
> >     uint32_t crc;
> > 
> 
> -- 
> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-54 Fax: (+49)-8142-66989-80 Email: [email protected]

-- 
Andreas Reichel
Dipl.-Phys. (Univ.)
Software Consultant

[email protected], +49-174-3180074
TNG Technology Consulting GmbH, Betastr. 13a, 85774 Unterfoehring
Geschaeftsfuehrer: Henrik Klagges, Dr. Robert Dahlke, Gerhard Mueller
Sitz: Unterfoehring * Amtsgericht Muenchen * HRB 135082

-- 
You received this message because you are subscribed to the Google Groups "EFI 
Boot Guard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/efibootguard-dev/20180528142339.GB2715%40iiotirae.
For more options, visit https://groups.google.com/d/optout.

Reply via email to