aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2016-11-03 18:12:03 -0400
committerRob Austein <sra@hactrn.net>2016-11-03 18:12:03 -0400
commite5d197ba16407ce5cb54213f08c0290ba3a4dd18 (patch)
tree65bf18dbc49a7e44a07a749e0a1f5aa34e424d95
parentbfc8465895e2f792f878119edf216d9b6c51cd1f (diff)
Fix sign error in ks_name_cmp(), confusion in hal_ks_index_fsck().
ks_name_cmp() was reporting inverted order when comparing two names which differ only by chunk number. hal_ks_index_fsck() was both broken and more complex than needed.
-rw-r--r--ks_index.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/ks_index.c b/ks_index.c
index 4f08e5e..fe4d1b8 100644
--- a/ks_index.c
+++ b/ks_index.c
@@ -49,7 +49,7 @@ static inline int ks_name_cmp(const hal_ks_name_t * const name1, const hal_ks_na
int cmp = hal_uuid_cmp(&name1->name, &name2->name);
if (cmp == 0)
- cmp = ((int) name2->chunk) - ((int) name1->chunk);
+ cmp = ((int) name1->chunk) - ((int) name2->chunk);
return cmp;
}
@@ -155,16 +155,13 @@ hal_error_t hal_ks_index_fsck(hal_ks_index_t *ksi)
ksi->size == 0 || ksi->used > ksi->size)
return HAL_ERROR_BAD_ARGUMENTS;
- int cur, prev = -1;
+ for (int i = 0; i < ksi->used; i++) {
- for (cur = 0; cur < ksi->used; cur++) {
+ const int cmp = i == 0 ? -1 : hal_uuid_cmp(&ksi->names[ksi->index[i - 1]].name,
+ &ksi->names[ksi->index[i ]].name);
- const int cmp = (prev < 0 ? -1 : hal_uuid_cmp(&ksi->names[ksi->index[prev]].name,
- &ksi->names[ksi->index[cur]].name));
-
- const uint8_t cur_chunk = ksi->names[ksi->index[cur]].chunk;
-
- const uint8_t prev_chunk = (prev < 0 ? 0 : ksi->names[ksi->index[prev]].chunk);
+ const uint8_t prev_chunk = i == 0 ? 0 : ksi->names[ksi->index[i - 1]].chunk;
+ const uint8_t cur_chunk = ksi->names[ksi->index[i ]].chunk;
if (cmp > 0)
return HAL_ERROR_KSI_INDEX_UUID_MISORDERED;