Commit 603221c6 authored by Yoni Fogel's avatar Yoni Fogel

Addresses #1576 Removed (return a-b) comparison trick in tests, added comments about the issue

git-svn-id: file:///svn/toku/tokudb@10392 c7de825b-a66e-492c-adef-691d508d4ae1
parent 784f4eb2
......@@ -64,6 +64,7 @@ int toku_keycompare (bytevec key1, ITEMLEN key1len, bytevec key2, ITEMLEN key2le
}
#else
/* unroll that one four times */
// when a and b are chars, return a-b is safe here because return type is int. No over/underflow possible.
int toku_keycompare (bytevec key1, ITEMLEN key1len, bytevec key2, ITEMLEN key2len) {
int comparelen = key1len<key2len ? key1len : key2len;
const unsigned char *k1;
......@@ -83,6 +84,7 @@ int toku_keycompare (bytevec key1, ITEMLEN key1len, bytevec key2, ITEMLEN key2le
return (int)*k1-(int)*k2;
}
}
//See #1576. For very large keylengths this is a problem. Our maximum keysize is << INT_MAX so this is not an issue.
return key1len-key2len;
}
......
......@@ -23,7 +23,9 @@ static inline int intcmp(DB *db __attribute__((__unused__)), const DBT* a, const
int x = *(int*)a->data;
int y = *(int*)b->data;
return x - y;
if (x<y) return -1;
if (x>y) return 1;
return 0;
}
......
......@@ -63,13 +63,16 @@ static inline int
int_cmp (const toku_point* a, const toku_point*b) {
int x = *(int*)a;
int y = *(int*)b;
return x -y;
if (x<y) return -1;
if (x>y) return 1;
return 0;
}
static inline int
char_cmp (const TXNID a, const TXNID b) {
int x = (char)a;
int y = (char)b;
//x-y is safe because no over/underflow is possible. Range of values is 8bit
return x -y;
}
......
......@@ -97,7 +97,9 @@ int_dbt_cmp (DB *db, const DBT *a, const DBT *b) {
int x = *(int *) a->data;
int y = *(int *) b->data;
return x - y;
if (x<y) return -1;
if (x>y) return 1;
return 0;
}
#if !TOKU_WINDOWS
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment