summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2004-12-11 07:28:06 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2004-12-11 07:28:06 +0000
commit53d216d5a5e0b85f17a8d9e08615a2ede2dba395 (patch)
treec965ca8b885810bfbe91d33d83cc87a5bd43ff87
parent8bde63b62b3467dc07b8da5f0bd53d8b66789c79 (diff)
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@
-rw-r--r--sbin/disklabel/editor.c14
1 files 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 <Todd.Miller@courtesan.com>
@@ -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 <sys/types.h>
@@ -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);