From: krw Date: Sat, 4 Mar 2023 21:22:51 +0000 (+0000) Subject: Use nitems() in the simple iterations over mbr->mbr_prt[]. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=5f7fe693f69a769e97d438ec6fd2d74ee8350f79;p=openbsd Use nitems() in the simple iterations over mbr->mbr_prt[]. No intentional functional change. --- diff --git a/sbin/fdisk/cmd.c b/sbin/fdisk/cmd.c index 7a9aeec1000..014852b8014 100644 --- a/sbin/fdisk/cmd.c +++ b/sbin/fdisk/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.166 2023/03/04 14:47:18 krw Exp $ */ +/* $OpenBSD: cmd.c,v 1.167 2023/03/04 21:22:51 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -385,9 +385,9 @@ Xprint(const char *args, struct mbr *mbr) int Xwrite(const char *args, struct mbr *mbr) { - int i, n; + unsigned int i, n; - for (i = 0, n = 0; i < NDOSPART; i++) + for (i = 0, n = 0; i < nitems(mbr->mbr_prt); i++) if (mbr->mbr_prt[i].prt_id == DOSPTYP_OPENBSD) n++; if (n > 1) { @@ -493,7 +493,7 @@ Xflag(const char *args, struct mbr *mbr) gp[i].gp_attrs = 0; } } else { - for (i = 0; i < NDOSPART; i++) { + for (i = 0; i < nitems(mbr->mbr_prt); i++) { if (i == pn) mbr->mbr_prt[i].prt_flag = DOSACTIVE; else diff --git a/sbin/fdisk/mbr.c b/sbin/fdisk/mbr.c index 6e6b6c58caf..ef88ed4cb4a 100644 --- a/sbin/fdisk/mbr.c +++ b/sbin/fdisk/mbr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mbr.c,v 1.121 2022/07/26 14:30:37 krw Exp $ */ +/* $OpenBSD: mbr.c,v 1.122 2023/03/04 21:22:51 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -145,7 +145,7 @@ mbr_to_dos_mbr(const struct mbr *mbr, struct dos_mbr *dos_mbr) void MBR_print(const struct mbr *mbr, const char *units) { - int i; + unsigned int i; DISK_printgeometry("s"); @@ -153,7 +153,7 @@ MBR_print(const struct mbr *mbr, const char *units) printf("Signature: 0x%X\n", (int)mbr->mbr_signature); PRT_print_parthdr(); - for (i = 0; i < NDOSPART; i++) + for (i = 0; i < nitems(mbr->mbr_prt); i++) PRT_print_part(i, &mbr->mbr_prt[i], units); } @@ -198,7 +198,7 @@ MBR_valid_prt(const struct mbr *mbr) return 1; /* All zeros struct dos_mbr is editable. */ nprt = 0; - for (i = 0; i < NDOSPART; i++) { + for (i = 0; i < nitems(mbr->mbr_prt); i++) { bs = mbr->mbr_prt[i].prt_bs; ns = mbr->mbr_prt[i].prt_ns; id = mbr->mbr_prt[i].prt_id; diff --git a/sbin/fdisk/user.c b/sbin/fdisk/user.c index f4389ab18e6..27821fe263b 100644 --- a/sbin/fdisk/user.c +++ b/sbin/fdisk/user.c @@ -1,4 +1,4 @@ -/* $OpenBSD: user.c,v 1.84 2022/07/25 17:45:16 krw Exp $ */ +/* $OpenBSD: user.c,v 1.85 2023/03/04 21:22:51 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -117,7 +117,7 @@ USER_print_disk(const int verbosity) { struct mbr mbr; uint64_t lba_self, lba_firstembr; - int i; + unsigned int i; lba_self = lba_firstembr = 0; @@ -160,7 +160,7 @@ USER_print_disk(const int verbosity) MBR_print(&mbr, "s"); - for (lba_self = i = 0; i < 4; i++) + for (lba_self = i = 0; i < nitems(mbr.mbr_prt); i++) if (mbr.mbr_prt[i].prt_id == DOSPTYP_EXTEND || mbr.mbr_prt[i].prt_id == DOSPTYP_EXTENDL) { lba_self = mbr.mbr_prt[i].prt_bs;