Fix memncmp(): Do not memcmp twice

vmware
Hallvard B Furuseth 14 years ago
parent 86b40907d4
commit ab0d6fa05e
  1. 15
      libraries/libmdb/mdb.c

@ -333,15 +333,14 @@ static int memnrcmp(const void *s1, size_t n1,
static int static int
memncmp(const void *s1, size_t n1, const void *s2, size_t n2) memncmp(const void *s1, size_t n1, const void *s2, size_t n2)
{ {
if (n1 < n2) { int diff, len_diff = -1;
if (memcmp(s1, s2, n1) == 0)
return -1; if (n1 >= n2) {
} len_diff = (n1 > n2);
else if (n1 > n2) { n1 = n2;
if (memcmp(s1, s2, n2) == 0)
return 1;
} }
return memcmp(s1, s2, n1); diff = memcmp(s1, s2, n1);
return diff ? diff : len_diff;
} }
static int static int

Loading…
Cancel
Save