Re: [PATCH v2] lib/string.c: implement a basic bcmp

From: Steven Rostedt
Date: Wed Mar 13 2019 - 15:01:39 EST


On Wed, 13 Mar 2019 11:51:09 -0700
Nick Desaulniers <ndesaulniers@xxxxxxxxxx> wrote:


> > This is confusing where the comment says "like memcmp but .." and then
> > just returns memcmp() unmodified. If anything, I would expect to see
> >
> > return !!memcmp(cs, ct, conut);
>
> That's more work than strictly needed. memcmp already provides the
> semantics of bcmp. memcmp just provides more meaning to the
> signedness of the return code, whereas bcmp does not.

I figured you would say as much ;-)

>
> >
> > or have a better comment explaining why its the same.
>
> I could add something about "the signedness of the return code not
> providing any meaning." What would you like to see in such a comment?

I think it's the wording that bothers me:

+ * bcmp - Like memcmp but a non-zero return code simply indicates a non-match.

What about:

* bcmp - Like memcmp but non-zero only means a non-match

Then in the description say that bcmp() callers must not expect
anything more than zero and non-zero, as different implementations only
need to return non-zero for non matches. The non-zero has no other
meaning like it does in memcmp(). You could add that memcmp() itself is
one implementation of bcmp() but not vice versa.

-- Steve