From 5eddaeade6c4574a93516b1183e3283382324179 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Fri, 4 Sep 2020 07:58:03 +0200 Subject: [PATCH] Use an unsigned integer for the number of dives Because the dive_count variable is decremented, it doesn't contain the total number of dives, but the index of the last dive. A negative number indicates no dives. The same result can be obtained by using the total number of dives directly. That's not only more intuitive, but also fixes a -Wsign-compare compiler warning. --- src/cochran_commander.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cochran_commander.c b/src/cochran_commander.c index 63a00ba..7e8348e 100644 --- a/src/cochran_commander.c +++ b/src/cochran_commander.c @@ -621,7 +621,7 @@ cochran_commander_find_fingerprint(cochran_commander_device_t *device, cochran_d // We track profile ringbuffer usage to determine which dives have profile data int profile_capacity_remaining = device->layout->rb_profile_end - device->layout->rb_profile_begin; - int dive_count = -1; + unsigned int dive_count = 0; data->fp_dive_num = -1; // Start at end of log @@ -629,7 +629,6 @@ cochran_commander_find_fingerprint(cochran_commander_device_t *device, cochran_d dive_count = data->dive_count; else dive_count = device->layout->rb_logbook_entry_count; - dive_count--; unsigned int sample_read_size = 0; data->invalid_profile_dive_num = -1; @@ -676,7 +675,7 @@ cochran_commander_find_fingerprint(cochran_commander_device_t *device, cochran_d // Loop through dives to find FP, Accumulate profile data size, // and find the last dive with invalid profile - for (unsigned int i = 0; i <= dive_count; ++i) { + for (unsigned int i = 0; i < dive_count; ++i) { unsigned int idx = (device->layout->rb_logbook_entry_count + head_dive - (i + 1)) % device->layout->rb_logbook_entry_count; unsigned char *log_entry = data->logbook + idx * device->layout->rb_logbook_entry_size;