Skip to content

Commit 8650022

Browse files
committed
Merge branch 'jk/prio-queue-sign-compare-fix'
Type clean-up. * jk/prio-queue-sign-compare-fix: prio-queue: use size_t rather than int for size
2 parents 77825f7 + 62e745c commit 8650022

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

negotiator/skipping.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ static int push_parent(struct data *data, struct entry *entry,
134134
struct entry *parent_entry;
135135

136136
if (to_push->object.flags & SEEN) {
137-
int i;
138137
if (to_push->object.flags & POPPED)
139138
/*
140139
* The entry for this commit has already been popped,
@@ -145,7 +144,7 @@ static int push_parent(struct data *data, struct entry *entry,
145144
/*
146145
* Find the existing entry and use it.
147146
*/
148-
for (i = 0; i < data->rev_list.nr; i++) {
147+
for (size_t i = 0; i < data->rev_list.nr; i++) {
149148
parent_entry = data->rev_list.array[i].data;
150149
if (parent_entry->commit == to_push)
151150
goto parent_found;
@@ -248,7 +247,7 @@ static int ack(struct fetch_negotiator *n, struct commit *c)
248247
static void release(struct fetch_negotiator *n)
249248
{
250249
struct data *data = n->data;
251-
for (int i = 0; i < data->rev_list.nr; i++)
250+
for (size_t i = 0; i < data->rev_list.nr; i++)
252251
free(data->rev_list.array[i].data);
253252
clear_prio_queue(&data->rev_list);
254253
FREE_AND_NULL(data);

prio-queue.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
#include "git-compat-util.h"
22
#include "prio-queue.h"
33

4-
static inline int compare(struct prio_queue *queue, int i, int j)
4+
static inline int compare(struct prio_queue *queue, size_t i, size_t j)
55
{
66
int cmp = queue->compare(queue->array[i].data, queue->array[j].data,
77
queue->cb_data);
88
if (!cmp)
9-
cmp = queue->array[i].ctr - queue->array[j].ctr;
9+
cmp = (queue->array[i].ctr > queue->array[j].ctr) -
10+
(queue->array[i].ctr < queue->array[j].ctr);
1011
return cmp;
1112
}
1213

13-
static inline void swap(struct prio_queue *queue, int i, int j)
14+
static inline void swap(struct prio_queue *queue, size_t i, size_t j)
1415
{
1516
SWAP(queue->array[i], queue->array[j]);
1617
}
1718

1819
void prio_queue_reverse(struct prio_queue *queue)
1920
{
20-
int i, j;
21+
size_t i, j;
2122

2223
if (queue->compare)
2324
BUG("prio_queue_reverse() on non-LIFO queue");
25+
if (!queue->nr)
26+
return;
2427
for (i = 0; i < (j = (queue->nr - 1) - i); i++)
2528
swap(queue, i, j);
2629
}
@@ -35,7 +38,7 @@ void clear_prio_queue(struct prio_queue *queue)
3538

3639
void prio_queue_put(struct prio_queue *queue, void *thing)
3740
{
38-
int ix, parent;
41+
size_t ix, parent;
3942

4043
/* Append at the end */
4144
ALLOC_GROW(queue->array, queue->nr + 1, queue->alloc);
@@ -58,7 +61,7 @@ void prio_queue_put(struct prio_queue *queue, void *thing)
5861
void *prio_queue_get(struct prio_queue *queue)
5962
{
6063
void *result;
61-
int ix, child;
64+
size_t ix, child;
6265

6366
if (!queue->nr)
6467
return NULL;

prio-queue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct prio_queue {
3030
prio_queue_compare_fn compare;
3131
unsigned insertion_ctr;
3232
void *cb_data;
33-
int alloc, nr;
33+
size_t alloc, nr;
3434
struct prio_queue_entry *array;
3535
};
3636

0 commit comments

Comments
 (0)