Skip to content

Commit abf24a3

Browse files
committed
examples: avoid conversion warnings when calculating progress
When computing the progress, we perform some arithmetics that are implicitly converting from `size_t` to `int`. In one case we're calclulating a percentage, so we know that it should always be in the range of [0,100] and thus we're fine. In the other case we convert from bytes to kilobytes -- this should be stored in a `size_t` to avoid loss of precision, even though it probably won't matter due to limited download rates.
1 parent e7bb1fe commit abf24a3

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

examples/clone.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ static void print_progress(const progress_data *pd)
1717
0;
1818

1919
int checkout_percent = pd->total_steps > 0
20-
? (100 * pd->completed_steps) / pd->total_steps
20+
? (int)((100 * pd->completed_steps) / pd->total_steps)
2121
: 0;
22-
int kbytes = pd->fetch_progress.received_bytes / 1024;
22+
size_t kbytes = pd->fetch_progress.received_bytes / 1024;
2323

2424
if (pd->fetch_progress.total_objects &&
2525
pd->fetch_progress.received_objects == pd->fetch_progress.total_objects) {
2626
printf("Resolving deltas %d/%d\r",
2727
pd->fetch_progress.indexed_deltas,
2828
pd->fetch_progress.total_deltas);
2929
} else {
30-
printf("net %3d%% (%4d kb, %5d/%5d) / idx %3d%% (%5d/%5d) / chk %3d%% (%4" PRIuZ "/%4" PRIuZ ") %s\n",
30+
printf("net %3d%% (%4"PRIuZ" kb, %5d/%5d) / idx %3d%% (%5d/%5d) / chk %3d%% (%4" PRIuZ "/%4" PRIuZ ") %s\n",
3131
network_percent, kbytes,
3232
pd->fetch_progress.received_objects, pd->fetch_progress.total_objects,
3333
index_percent, pd->fetch_progress.indexed_objects, pd->fetch_progress.total_objects,

0 commit comments

Comments
 (0)