From 53d216d5a5e0b85f17a8d9e08615a2ede2dba395 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Sat, 11 Dec 2004 07:28:06 +0000 Subject: A compare function for heapsort(3) should not just subtract two offsets, it does not work if the difference is large. Problem found by Jean-Gerard Pailloncyi who had false warnings of overlapping partitions. ok millert@ tedu@ --- sbin/disklabel/editor.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c index aa81c12bfee..1eacc849e26 100644 --- a/sbin/disklabel/editor.c +++ b/sbin/disklabel/editor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: editor.c,v 1.97 2004/11/06 18:57:59 otto Exp $ */ +/* $OpenBSD: editor.c,v 1.98 2004/12/11 07:28:05 otto Exp $ */ /* * Copyright (c) 1997-2000 Todd C. Miller @@ -17,7 +17,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: editor.c,v 1.97 2004/11/06 18:57:59 otto Exp $"; +static char rcsid[] = "$OpenBSD: editor.c,v 1.98 2004/12/11 07:28:05 otto Exp $"; #endif /* not lint */ #include @@ -978,7 +978,12 @@ partition_cmp(const void *e1, const void *e2) struct partition *p1 = *(struct partition **)e1; struct partition *p2 = *(struct partition **)e2; - return((int)(p1->p_offset - p2->p_offset)); + if (p1->p_offset < p2->p_offset) + return -1; + else if (p1->p_offset > p2->p_offset) + return 1; + else + return 0; } char * @@ -1183,7 +1188,8 @@ has_overlap(struct disklabel *lp, u_int32_t *freep, int resolve) / sizeof(**spp); printf("\nError, partitions %c and %c overlap:\n", 'a' + i, 'a' + j); - puts(" size offset fstype [fsize bsize cpg]"); + printf("# %13.13s %13.13s fstype " + "[fsize bsize cpg]\n", "size", "offset"); display_partition(stdout, lp, NULL, i, 0); display_partition(stdout, lp, NULL, j, 0); -- cgit v1.2.3