Rewrite SimpleString::StrCmp() (3)

Take your pick :-)
Looks good to me.

On 11 Aug, 2014, at 2:21 pm, arstrube <notifications@github.com> wrote:

> In src/CppUTest/SimpleString.cpp:
> 
> > @@ -98,14 +95,11 @@ size_t SimpleString::StrLen(const char* str)
> >  
> >  int SimpleString::StrNCmp(const char* s1, const char* s2, size_t n)
> >  {
> > -    while (n) {
> > -         if (*s1 != *s2)
> > -             return *(unsigned char *) s1 - *(unsigned char *) s2;
> > -         if (*s1 == 0)
> > -             return 0;
> > -         n--, s1++, s2++;
> > +    while (n && *s1 && *s1 == *s2) {
> > +        n--, s1++, s2++;
> > +        if (n == 0) return 0;
> This does work:
> 
> while (n > 1 && *s1 && *s1 == *s2) {
>     n--, s1++, s2++;
> }
> return *(unsigned char *) s1 - *(unsigned char *) s2;
> —
> Reply to this email directly or view it on GitHub.
>