* 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
This commit is contained in:
Axel Dörfler 2008-03-19 08:41:00 +00:00
parent eff1a72904
commit 974e087ef1

View File

@ -2301,7 +2301,7 @@ compareKeys(type_code type, const void *key1, int keyLength1,
// give a meaningful result // give a meaningful result
if (key1 == NULL && key2 != NULL) if (key1 == NULL && key2 != NULL)
return 1; return 1;
else if (key2 == NULL && key1 != NULL) if (key2 == NULL && key1 != NULL)
return -1; return -1;
return 0; return 0;
@ -2310,11 +2310,8 @@ compareKeys(type_code type, const void *key1, int keyLength1,
switch (type) { switch (type) {
case B_STRING_TYPE: case B_STRING_TYPE:
{ {
int len = min_c(keyLength1, keyLength2); int result = memcmp(key1, key2, min_c(keyLength1, keyLength2));
int result = strncmp((const char *)key1, (const char *)key2, len); if (result == 0)
if (result == 0
&& !(((const char *)key1)[len] == '\0' && ((const char *)key2)[len] == '\0'))
result = keyLength1 - keyLength2; result = keyLength1 - keyLength2;
return result; return result;
@ -2328,7 +2325,7 @@ compareKeys(type_code type, const void *key1, int keyLength1,
case B_UINT32_TYPE: case B_UINT32_TYPE:
if (*(uint32 *)key1 == *(uint32 *)key2) if (*(uint32 *)key1 == *(uint32 *)key2)
return 0; return 0;
else if (*(uint32 *)key1 > *(uint32 *)key2) if (*(uint32 *)key1 > *(uint32 *)key2)
return 1; return 1;
return -1; return -1;
@ -2337,7 +2334,7 @@ compareKeys(type_code type, const void *key1, int keyLength1,
case B_INT64_TYPE: case B_INT64_TYPE:
if (*(int64 *)key1 == *(int64 *)key2) if (*(int64 *)key1 == *(int64 *)key2)
return 0; return 0;
else if (*(int64 *)key1 > *(int64 *)key2) if (*(int64 *)key1 > *(int64 *)key2)
return 1; return 1;
return -1; return -1;
@ -2345,7 +2342,7 @@ compareKeys(type_code type, const void *key1, int keyLength1,
case B_UINT64_TYPE: case B_UINT64_TYPE:
if (*(uint64 *)key1 == *(uint64 *)key2) if (*(uint64 *)key1 == *(uint64 *)key2)
return 0; return 0;
else if (*(uint64 *)key1 > *(uint64 *)key2) if (*(uint64 *)key1 > *(uint64 *)key2)
return 1; return 1;
return -1; return -1;