Mon Mar 16 13:33:36 2009 UTC ()
fix sign-compare issues


(lukem)
diff -r1.30 -r1.31 src/sbin/disklabel/interact.c

cvs diff -r1.30 -r1.31 src/sbin/disklabel/interact.c (expand / switch to unified diff)

--- src/sbin/disklabel/interact.c 2006/11/26 16:16:31 1.30
+++ src/sbin/disklabel/interact.c 2009/03/16 13:33:36 1.31
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: interact.c,v 1.30 2006/11/26 16:16:31 jmmv Exp $ */ 1/* $NetBSD: interact.c,v 1.31 2009/03/16 13:33:36 lukem Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1997 Christos Zoulas. All rights reserved. 4 * Copyright (c) 1997 Christos Zoulas. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software 14 * 3. All advertising materials mentioning features or use of this software
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#if HAVE_NBTOOL_CONFIG_H 32#if HAVE_NBTOOL_CONFIG_H
33#include "nbtool_config.h" 33#include "nbtool_config.h"
34#endif 34#endif
35 35
36#include <sys/cdefs.h> 36#include <sys/cdefs.h>
37#ifndef lint 37#ifndef lint
38__RCSID("$NetBSD: interact.c,v 1.30 2006/11/26 16:16:31 jmmv Exp $"); 38__RCSID("$NetBSD: interact.c,v 1.31 2009/03/16 13:33:36 lukem Exp $");
39#endif /* lint */ 39#endif /* lint */
40 40
41#include <sys/param.h> 41#include <sys/param.h>
42#define FSTYPENAMES 42#define FSTYPENAMES
43#define DKTYPENAMES 43#define DKTYPENAMES
44 44
45#include <err.h> 45#include <err.h>
46#include <stdio.h> 46#include <stdio.h>
47#include <string.h> 47#include <string.h>
48#include <stdlib.h> 48#include <stdlib.h>
49 49
50#if HAVE_NBTOOL_CONFIG_H 50#if HAVE_NBTOOL_CONFIG_H
51#define getmaxpartitions() MAXPARTITIONS 51#define getmaxpartitions() MAXPARTITIONS
@@ -498,30 +498,30 @@ cmd_part(struct disklabel *lp, char *s,  @@ -498,30 +498,30 @@ cmd_part(struct disklabel *lp, char *s,
498 if (line[1] == '\0' && 498 if (line[1] == '\0' &&
499 line[0] >= 'a' && line[0] < 'a' + getmaxpartitions()) { 499 line[0] >= 'a' && line[0] < 'a' + getmaxpartitions()) {
500 struct partition *cp = lp->d_partitions; 500 struct partition *cp = lp->d_partitions;
501 501
502 if ((cp[line[0] - 'a'].p_offset + 502 if ((cp[line[0] - 'a'].p_offset +
503 cp[line[0] - 'a'].p_size) >= lp->d_secperunit) { 503 cp[line[0] - 'a'].p_size) >= lp->d_secperunit) {
504 printf("Bad offset `%s'\n", line); 504 printf("Bad offset `%s'\n", line);
505 continue; 505 continue;
506 } else { 506 } else {
507 p->p_offset = cp[line[0] - 'a'].p_offset + 507 p->p_offset = cp[line[0] - 'a'].p_offset +
508 cp[line[0] - 'a'].p_size; 508 cp[line[0] - 'a'].p_size;
509 } 509 }
510 } else { 510 } else {
511 if ((i = getnum(lp, line, 0)) == -1) { 511 if ((i = getnum(lp, line, 0)) == -1 || i < 0) {
512 printf("Bad offset `%s'\n", line); 512 printf("Bad offset `%s'\n", line);
513 continue; 513 continue;
514 } else if (i > lp->d_secperunit) { 514 } else if ((uint32_t)i > lp->d_secperunit) {
515 printf("Offset `%s' out of range\n", line); 515 printf("Offset `%s' out of range\n", line);
516 continue; 516 continue;
517 } 517 }
518 p->p_offset = i; 518 p->p_offset = i;
519 } 519 }
520 break; 520 break;
521 } 521 }
522 for (;;) { 522 for (;;) {
523 defnum(lp, def, p->p_size); 523 defnum(lp, def, p->p_size);
524 i = getinput(":", "Partition size ('$' for all remaining)", 524 i = getinput(":", "Partition size ('$' for all remaining)",
525 def, line); 525 def, line);
526 if (i == -1) 526 if (i == -1)
527 return; 527 return;
@@ -537,27 +537,27 @@ cmd_part(struct disklabel *lp, char *s,  @@ -537,27 +537,27 @@ cmd_part(struct disklabel *lp, char *s,
537 continue; 537 continue;
538 } 538 }
539 p->p_size = i; 539 p->p_size = i;
540 break; 540 break;
541 } 541 }
542 542
543 if (memcmp(&ps, p, sizeof(ps))) 543 if (memcmp(&ps, p, sizeof(ps)))
544 showpartition(stdout, lp, part, Cflag); 544 showpartition(stdout, lp, part, Cflag);
545 if (chaining) { 545 if (chaining) {
546 int offs = -1; 546 int offs = -1;
547 struct partition *cp = lp->d_partitions; 547 struct partition *cp = lp->d_partitions;
548 for (i = 0; i < lp->d_npartitions; i++) { 548 for (i = 0; i < lp->d_npartitions; i++) {
549 if (cp[i].p_fstype != FS_UNUSED) { 549 if (cp[i].p_fstype != FS_UNUSED) {
550 if (offs != -1 && cp[i].p_offset != offs) { 550 if (offs != -1 && cp[i].p_offset != (uint32_t)offs) {
551 cp[i].p_offset = offs; 551 cp[i].p_offset = offs;
552 showpartition(stdout, lp, i, Cflag); 552 showpartition(stdout, lp, i, Cflag);
553 } 553 }
554 offs = cp[i].p_offset + cp[i].p_size; 554 offs = cp[i].p_offset + cp[i].p_size;
555 } 555 }
556 } 556 }
557 } 557 }
558} 558}
559 559
560 560
561static void 561static void
562cmd_label(struct disklabel *lp, char *s, int fd) 562cmd_label(struct disklabel *lp, char *s, int fd)
563{ 563{
@@ -640,29 +640,29 @@ getinput(const char *sep, const char *pr @@ -640,29 +640,29 @@ getinput(const char *sep, const char *pr
640} 640}
641 641
642static int 642static int
643alphacmp(const void *a, const void *b) 643alphacmp(const void *a, const void *b)
644{ 644{
645 645
646 return (strcasecmp(*(const char * const*)a, *(const char * const*)b)); 646 return (strcasecmp(*(const char * const*)a, *(const char * const*)b));
647} 647}
648 648
649 649
650static void 650static void
651dumpnames(const char *prompt, const char * const *olist, size_t numentries) 651dumpnames(const char *prompt, const char * const *olist, size_t numentries)
652{ 652{
653 int i, w; 653 int w;
654 int entry; 654 size_t i, entry, lines;
655 int columns, width, lines; 655 int columns, width;
656 const char *p; 656 const char *p;
657 const char **list; 657 const char **list;
658 658
659 if ((list = (const char **)malloc(sizeof(char *) * numentries)) == NULL) 659 if ((list = (const char **)malloc(sizeof(char *) * numentries)) == NULL)
660 err(1, "malloc"); 660 err(1, "malloc");
661 width = 0; 661 width = 0;
662 printf("%s:\n", prompt); 662 printf("%s:\n", prompt);
663 for (i = 0; i < numentries; i++) { 663 for (i = 0; i < numentries; i++) {
664 list[i] = olist[i]; 664 list[i] = olist[i];
665 w = strlen(list[i]); 665 w = strlen(list[i]);
666 if (w > width) 666 if (w > width)
667 width = w; 667 width = w;
668 } 668 }