avoid subtraction of values larger than int in qsort(3) comparison callbacks tweak + ok tb@
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
diff --git a/lib/pack_create.c b/lib/pack_create.c
index 14aa435..c4297f6 100644
--- a/lib/pack_create.c
+++ b/lib/pack_create.c
@@ -162,8 +162,10 @@ delta_order_cmp(const void *pa, const void *pb)
cmp = strcmp(a->path, b->path);
if (cmp != 0)
return cmp;
- if (a->mtime != b->mtime)
- return a->mtime - b->mtime;
+ if (a->mtime < b->mtime)
+ return -1;
+ if (a->mtime > b->mtime)
+ return 1;
return got_object_id_cmp(&a->id, &b->id);
}
@@ -1514,13 +1516,21 @@ write_order_cmp(const void *pa, const void *pb)
b = *(struct got_pack_meta **)pb;
ahd = (a->head == NULL) ? a : a->head;
bhd = (b->head == NULL) ? b : b->head;
- if (ahd->mtime != bhd->mtime)
- return bhd->mtime - ahd->mtime;
- if (ahd != bhd)
- return (uintptr_t)bhd - (uintptr_t)ahd;
+ if (bhd->mtime < ahd->mtime)
+ return -1;
+ if (bhd->mtime > ahd->mtime)
+ return 1;
+ if (bhd < ahd)
+ return -1;
+ if (bhd > ahd)
+ return 1;
if (a->nchain != b->nchain)
return a->nchain - b->nchain;
- return a->mtime - b->mtime;
+ if (a->mtime < b->mtime)
+ return -1;
+ if (a->mtime > b->mtime)
+ return 1;
+ return got_object_id_cmp(&a->id, &b->id);
}
static int