From: Hallvard B Furuseth Date: Wed, 29 Jun 2011 16:59:53 +0000 (+0200) Subject: Fix memncmp(): Do not memcmp twice X-Git-Tag: OPENLDAP_REL_ENG_2_4_27~148^2~171 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ab0d6fa05ed44d7c09b6c16db8d2b6fb2e0c3183;p=openldap Fix memncmp(): Do not memcmp twice --- diff --git a/libraries/libmdb/mdb.c b/libraries/libmdb/mdb.c index 426d6d178b..ad08e9db3e 100644 --- a/libraries/libmdb/mdb.c +++ b/libraries/libmdb/mdb.c @@ -333,15 +333,14 @@ static int memnrcmp(const void *s1, size_t n1, static int memncmp(const void *s1, size_t n1, const void *s2, size_t n2) { - if (n1 < n2) { - if (memcmp(s1, s2, n1) == 0) - return -1; - } - else if (n1 > n2) { - if (memcmp(s1, s2, n2) == 0) - return 1; + int diff, len_diff = -1; + + if (n1 >= n2) { + len_diff = (n1 > n2); + n1 = n2; } - return memcmp(s1, s2, n1); + diff = memcmp(s1, s2, n1); + return diff ? diff : len_diff; } static int