Skip to content

Commit

Permalink
Merge branch 'rs/clarify-entry-cmp-sslice'
Browse files Browse the repository at this point in the history
* rs/clarify-entry-cmp-sslice:
  refs: use strncmp() instead of strlen() and memcmp()
  • Loading branch information
gitster committed Jan 24, 2013
2 parents fa2f83c + c971ddf commit f12e49a
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,12 @@ struct string_slice {

static int ref_entry_cmp_sslice(const void *key_, const void *ent_)
{
struct string_slice *key = (struct string_slice *)key_;
struct ref_entry *ent = *(struct ref_entry **)ent_;
int entlen = strlen(ent->name);
int cmplen = key->len < entlen ? key->len : entlen;
int cmp = memcmp(key->str, ent->name, cmplen);
const struct string_slice *key = key_;
const struct ref_entry *ent = *(const struct ref_entry * const *)ent_;
int cmp = strncmp(key->str, ent->name, key->len);
if (cmp)
return cmp;
return key->len - entlen;
return '\0' - (unsigned char)ent->name[key->len];
}

/*
Expand Down

0 comments on commit f12e49a

Please sign in to comment.