diff --git a/negotiator/skipping.c b/negotiator/skipping.c index abedb70a48..616df6bf3a 100644 --- a/negotiator/skipping.c +++ b/negotiator/skipping.c @@ -134,7 +134,6 @@ static int push_parent(struct data *data, struct entry *entry, struct entry *parent_entry; if (to_push->object.flags & SEEN) { - int i; if (to_push->object.flags & POPPED) /* * The entry for this commit has already been popped, @@ -145,7 +144,7 @@ static int push_parent(struct data *data, struct entry *entry, /* * Find the existing entry and use it. */ - for (i = 0; i < data->rev_list.nr; i++) { + for (size_t i = 0; i < data->rev_list.nr; i++) { parent_entry = data->rev_list.array[i].data; if (parent_entry->commit == to_push) goto parent_found; @@ -248,7 +247,7 @@ static int ack(struct fetch_negotiator *n, struct commit *c) static void release(struct fetch_negotiator *n) { struct data *data = n->data; - for (int i = 0; i < data->rev_list.nr; i++) + for (size_t i = 0; i < data->rev_list.nr; i++) free(data->rev_list.array[i].data); clear_prio_queue(&data->rev_list); FREE_AND_NULL(data); diff --git a/prio-queue.c b/prio-queue.c index 450775a374..ec33ac27db 100644 --- a/prio-queue.c +++ b/prio-queue.c @@ -1,26 +1,29 @@ #include "git-compat-util.h" #include "prio-queue.h" -static inline int compare(struct prio_queue *queue, int i, int j) +static inline int compare(struct prio_queue *queue, size_t i, size_t j) { int cmp = queue->compare(queue->array[i].data, queue->array[j].data, queue->cb_data); if (!cmp) - cmp = queue->array[i].ctr - queue->array[j].ctr; + cmp = (queue->array[i].ctr > queue->array[j].ctr) - + (queue->array[i].ctr < queue->array[j].ctr); return cmp; } -static inline void swap(struct prio_queue *queue, int i, int j) +static inline void swap(struct prio_queue *queue, size_t i, size_t j) { SWAP(queue->array[i], queue->array[j]); } void prio_queue_reverse(struct prio_queue *queue) { - int i, j; + size_t i, j; if (queue->compare) BUG("prio_queue_reverse() on non-LIFO queue"); + if (!queue->nr) + return; for (i = 0; i < (j = (queue->nr - 1) - i); i++) swap(queue, i, j); } @@ -35,7 +38,7 @@ void clear_prio_queue(struct prio_queue *queue) void prio_queue_put(struct prio_queue *queue, void *thing) { - int ix, parent; + size_t ix, parent; /* Append at the end */ ALLOC_GROW(queue->array, queue->nr + 1, queue->alloc); @@ -58,7 +61,7 @@ void prio_queue_put(struct prio_queue *queue, void *thing) void *prio_queue_get(struct prio_queue *queue) { void *result; - int ix, child; + size_t ix, child; if (!queue->nr) return NULL; diff --git a/prio-queue.h b/prio-queue.h index 4f9a37e6be..36f370625f 100644 --- a/prio-queue.h +++ b/prio-queue.h @@ -30,7 +30,7 @@ struct prio_queue { prio_queue_compare_fn compare; unsigned insertion_ctr; void *cb_data; - int alloc, nr; + size_t alloc, nr; struct prio_queue_entry *array; };