ref: 5dfdaf27ae4bdfab84d4853612b21e460fbd1c75
parent: 08c696765fb280e41b2637fa17b49d9272c8f865
author: gkostka <[email protected]>
date: Mon Nov 23 13:12:26 EST 2015
Fix lru/lba compare functions: possible overflow Functions will not work for lba values: - 0x100000001ULL - 0x000000001UL It won't work also for 16 int architectures. So it is better to implement this functions using if/else if statements.
--- a/lwext4/ext4_bcache.c
+++ b/lwext4/ext4_bcache.c
@@ -42,18 +42,22 @@
#include <string.h>
#include <stdlib.h>
-static int
-ext4_bcache_lba_compare(struct ext4_buf *a,
- struct ext4_buf *b)
+static int ext4_bcache_lba_compare(struct ext4_buf *a, struct ext4_buf *b)
{
- return a->lba - b->lba;
+ if (a->lba > b->lba)
+ return 1;
+ else if (a->lba < b->lba)
+ return -1;
+ return 0;
}
-static int
-ext4_bcache_lru_compare(struct ext4_buf *a,
- struct ext4_buf *b)
+static int ext4_bcache_lru_compare(struct ext4_buf *a, struct ext4_buf *b)
{
- return a->lru_id - b->lru_id;
+ if (a->lru_id > b->lru_id)
+ return 1;
+ else if (a->lru_id < b->lru_id)
+ return -1;
+ return 0;
}
RB_GENERATE_INTERNAL(ext4_buf_lba, ext4_buf, lba_node,