From 974e087ef1deda8ca00349a2ec32b4b3956c2fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 19 Mar 2008 08:41:00 +0000 Subject: [PATCH] * If two equal keys were compared, the check for the key end was incorrect; only the length of the key matters, not if they are null terminated. It would still return the correct value, though, it would just access one byte beyond the buffer (which didn't really matter in this specific case). * Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24456 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp b/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp index b1aa4cdba6..d9596591a7 100644 --- a/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp +++ b/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp @@ -2301,7 +2301,7 @@ compareKeys(type_code type, const void *key1, int keyLength1, // give a meaningful result if (key1 == NULL && key2 != NULL) return 1; - else if (key2 == NULL && key1 != NULL) + if (key2 == NULL && key1 != NULL) return -1; return 0; @@ -2310,11 +2310,8 @@ compareKeys(type_code type, const void *key1, int keyLength1, switch (type) { case B_STRING_TYPE: { - int len = min_c(keyLength1, keyLength2); - int result = strncmp((const char *)key1, (const char *)key2, len); - - if (result == 0 - && !(((const char *)key1)[len] == '\0' && ((const char *)key2)[len] == '\0')) + int result = memcmp(key1, key2, min_c(keyLength1, keyLength2)); + if (result == 0) result = keyLength1 - keyLength2; return result; @@ -2328,7 +2325,7 @@ compareKeys(type_code type, const void *key1, int keyLength1, case B_UINT32_TYPE: if (*(uint32 *)key1 == *(uint32 *)key2) return 0; - else if (*(uint32 *)key1 > *(uint32 *)key2) + if (*(uint32 *)key1 > *(uint32 *)key2) return 1; return -1; @@ -2337,7 +2334,7 @@ compareKeys(type_code type, const void *key1, int keyLength1, case B_INT64_TYPE: if (*(int64 *)key1 == *(int64 *)key2) return 0; - else if (*(int64 *)key1 > *(int64 *)key2) + if (*(int64 *)key1 > *(int64 *)key2) return 1; return -1; @@ -2345,7 +2342,7 @@ compareKeys(type_code type, const void *key1, int keyLength1, case B_UINT64_TYPE: if (*(uint64 *)key1 == *(uint64 *)key2) return 0; - else if (*(uint64 *)key1 > *(uint64 *)key2) + if (*(uint64 *)key1 > *(uint64 *)key2) return 1; return -1;