[sheepdog] [PATCH] farm: fix comparison of empty sha1
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Tue Aug 7 13:55:02 CEST 2012
At Tue, 07 Aug 2012 19:21:10 +0800,
Liu Yuan wrote:
>
> On 08/07/2012 07:11 PM, MORITA Kazutaka wrote:
> > static inline int trunk_entry_no_sha1(struct trunk_entry_incore *entry)
> > {
> > - return !strlen((char *)entry->raw.sha1);
> > + unsigned char empty[SHA1_LEN] = {0};
> > +
> > + return memcmp(entry->raw.sha1, empty, SHA1_LEN) == 0;
> > }
> >
> > static inline void put_entry(struct trunk_entry_incore *entry)
> > --
>
> Could you explain what kind of problem the old code is?
If the first byte of entry->raw.sha1 is zero, strlen(entry->raw.sha1)
returns zero. What this function wants to do is to check
entry->raw.sha1 is filled with zero, isn't it?
Thanks,
Kazutaka
More information about the sheepdog
mailing list