summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a6da939)
raw | patch | inline | side by side (parent: a6da939)
author | Junio C Hamano <junkio@cox.net> | |
Tue, 6 Dec 2005 21:41:48 +0000 (13:41 -0800) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Wed, 7 Dec 2005 01:28:26 +0000 (17:28 -0800) |
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>
> 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>
object.c | patch | blob | history |
diff --git a/object.c b/object.c
index 427e14cae2deb42138a439f7b2d69d3e06bb9417..cf5931a9423cb2ecdd9f34e6c33ed0b714ce61bf 100644 (file)
--- a/object.c
+++ b/object.c
{
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)