[Cryptech-Commits] [sw/libhal] 01/03: Fix sign error in ks_name_cmp(), confusion in hal_ks_index_fsck().
git at cryptech.is
git at cryptech.is
Thu Nov 3 23:20:50 UTC 2016
This is an automated email from the git hooks/post-receive script.
sra at hactrn.net pushed a commit to branch ksng
in repository sw/libhal.
commit e5d197ba16407ce5cb54213f08c0290ba3a4dd18
Author: Rob Austein <sra at hactrn.net>
AuthorDate: Thu Nov 3 18:12:03 2016 -0400
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.
---
ks_index.c | 15 ++++++---------
1 file 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;
More information about the Commits
mailing list