Skip to content

Commit 2a85906

Browse files
Chandra Pratapgitster
authored andcommitted
reftable: change the type of array indices to 'size_t' in reftable/pq.c
The variables 'i', 'j', 'k' and 'min' are used as indices for 'pq->heap', which is an array. Additionally, 'pq->len' is of type 'size_t' and is often used to assign values to these variables. Hence, change the type of these variables from 'int' to 'size_t'. Mentored-by: Patrick Steinhardt <[email protected]> Mentored-by: Christian Couder <[email protected]> Signed-off-by: Chandra Pratap <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f1b60b7 commit 2a85906

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

reftable/pq.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ int pq_less(struct pq_entry *a, struct pq_entry *b)
2222

2323
struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)
2424
{
25-
int i = 0;
25+
size_t i = 0;
2626
struct pq_entry e = pq->heap[0];
2727
pq->heap[0] = pq->heap[pq->len - 1];
2828
pq->len--;
2929

3030
while (i < pq->len) {
31-
int min = i;
32-
int j = 2 * i + 1;
33-
int k = 2 * i + 2;
31+
size_t min = i;
32+
size_t j = 2 * i + 1;
33+
size_t k = 2 * i + 2;
3434
if (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i]))
3535
min = j;
3636
if (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min]))
@@ -46,14 +46,14 @@ struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)
4646

4747
void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e)
4848
{
49-
int i = 0;
49+
size_t i = 0;
5050

5151
REFTABLE_ALLOC_GROW(pq->heap, pq->len + 1, pq->cap);
5252
pq->heap[pq->len++] = *e;
5353

5454
i = pq->len - 1;
5555
while (i > 0) {
56-
int j = (i - 1) / 2;
56+
size_t j = (i - 1) / 2;
5757
if (pq_less(&pq->heap[j], &pq->heap[i]))
5858
break;
5959
SWAP(pq->heap[j], pq->heap[i]);

0 commit comments

Comments
 (0)