Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-12-07 00:41:48 +0300
committerJunio C Hamano <junkio@cox.net>2005-12-07 04:28:26 +0300
commite23eff8be92a2a2cb66b53deef020063cff285ed (patch)
tree014d940871fa860412d000ca329f9ef57ad12d46 /object.c
parenta6da9395a5b6d3df901ce0a6cb61d123f77d7342 (diff)
qsort() ptrdiff_t may be larger than int
Morten Welinder <mwelinder@gmail.com> writes: > The code looks wrong. It assumes that pointers are no larger than ints. > If pointers are larger than ints, the code does not necessarily compute > a consistent ordering and qsort is allowed to do whatever it wants. > > Morten > > static int compare_object_pointers(const void *a, const void *b) > { > const struct object * const *pa = a; > const struct object * const *pb = b; > return *pa - *pb; > } Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'object.c')
-rw-r--r--object.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/object.c b/object.c
index 427e14cae2..cf5931a942 100644
--- a/object.c
+++ b/object.c
@@ -82,7 +82,12 @@ static int compare_object_pointers(const void *a, const void *b)
{
const struct object * const *pa = a;
const struct object * const *pb = b;
- return *pa - *pb;
+ if (*pa == *pb)
+ return 0;
+ else if (*pa < *pb)
+ return -1;
+ else
+ return 1;
}
void set_object_refs(struct object *obj, struct object_refs *refs)