Skip to content

Commit f12e49a

Browse files
committed
Merge branch 'rs/clarify-entry-cmp-sslice'
* rs/clarify-entry-cmp-sslice: refs: use strncmp() instead of strlen() and memcmp()
2 parents fa2f83c + c971ddf commit f12e49a

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

refs.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,14 +333,12 @@ struct string_slice {
333333

334334
static int ref_entry_cmp_sslice(const void *key_, const void *ent_)
335335
{
336-
struct string_slice *key = (struct string_slice *)key_;
337-
struct ref_entry *ent = *(struct ref_entry **)ent_;
338-
int entlen = strlen(ent->name);
339-
int cmplen = key->len < entlen ? key->len : entlen;
340-
int cmp = memcmp(key->str, ent->name, cmplen);
336+
const struct string_slice *key = key_;
337+
const struct ref_entry *ent = *(const struct ref_entry * const *)ent_;
338+
int cmp = strncmp(key->str, ent->name, key->len);
341339
if (cmp)
342340
return cmp;
343-
return key->len - entlen;
341+
return '\0' - (unsigned char)ent->name[key->len];
344342
}
345343

346344
/*

0 commit comments

Comments
 (0)