From 0e604abd956efb0790eb412ac018c224db11d8c0 Mon Sep 17 00:00:00 2001 From: krw Date: Thu, 9 Sep 2021 12:36:45 +0000 Subject: [PATCH] Scan unit_types[] array using nitems() and eliminate the NULL sentinal entry. No functional change. --- sbin/fdisk/misc.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/sbin/fdisk/misc.c b/sbin/fdisk/misc.c index ce349826f53..5ffed50c542 100644 --- a/sbin/fdisk/misc.c +++ b/sbin/fdisk/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.82 2021/08/28 11:55:17 krw Exp $ */ +/* $OpenBSD: misc.c,v 1.83 2021/09/09 12:36:45 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -37,26 +37,21 @@ struct unit_type unit_types[] = { { "M" , 1024LL * 1024 , "Megabytes" }, { "G" , 1024LL * 1024 *1024 , "Gigabytes" }, { "T" , 1024LL * 1024 * 1024 * 1024 , "Terabytes" }, - { NULL , 0 , NULL }, }; int unit_lookup(const char *units) { - int i = 0; + unsigned int i; - if (units == NULL) - return SECTORS; - - while (unit_types[i].ut_abbr != NULL) { - if (strncasecmp(unit_types[i].ut_abbr, units, 1) == 0) - break; - i++; + if (units != NULL) { + for (i = 0; i < nitems(unit_types); i++) { + if (strncasecmp(unit_types[i].ut_abbr, units, 1) == 0) + return i; + } } - if (unit_types[i].ut_abbr == NULL) - return SECTORS; - return i; + return SECTORS; } void -- 2.20.1