From 22cecf786fe19ad2e246d06e46cf5b830c53c8e2 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 22 Jun 2021 11:50:06 +0200 Subject: [PATCH] cfdisk: do not use atoi() It's unnecessary to use atoi in this case. Addresses: https://github.com/karelzak/util-linux/issues/1358 Signed-off-by: Karel Zak --- disk-utils/cfdisk.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c index b8891316e..d7a9a4e3d 100644 --- a/disk-utils/cfdisk.c +++ b/disk-utils/cfdisk.c @@ -1322,6 +1322,15 @@ static char *get_mountpoint(struct cfdisk *cf, const char *tagname, const char * } #endif /* HAVE_LIBMOUNT */ +static inline int iszero(const char *str) +{ + const char *p; + + for (p = str; p && *p == '0'; p++); + + return !p || *p == '\0'; +} + static void extra_prepare_data(struct cfdisk *cf) { struct fdisk_partition *pa = get_current_partition(cf); @@ -1365,19 +1374,19 @@ static void extra_prepare_data(struct cfdisk *cf) /* for numeric data, only show non-zero rows */ if (!fdisk_partition_to_string(pa, cf->cxt, FDISK_FIELD_BSIZE, &data) && data) { - if (atoi(data)) + if (!iszero(data)) extra_insert_pair(l, "BSIZE:", data); free(data); } if (!fdisk_partition_to_string(pa, cf->cxt, FDISK_FIELD_CPG, &data) && data) { - if (atoi(data)) + if (!iszero(data)) extra_insert_pair(l, "CPG:", data); free(data); } if (!fdisk_partition_to_string(pa, cf->cxt, FDISK_FIELD_FSIZE, &data) && data) { - if (atoi(data)) + if (!iszero(data)) extra_insert_pair(l, "FSIZE:", data); free(data); }