Skip to content

Commit

Permalink
qsort() ptrdiff_t may be larger than int
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Dec 7, 2005
1 parent a6da939 commit e23eff8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e23eff8

Please sign in to comment.