]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
cfdisk: do not use atoi()
authorKarel Zak <kzak@redhat.com>
Tue, 22 Jun 2021 09:50:06 +0000 (11:50 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 22 Jun 2021 09:50:06 +0000 (11:50 +0200)
It's unnecessary to use atoi in this case.

Addresses: https://github.com/karelzak/util-linux/issues/1358
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/cfdisk.c

index b8891316eb541e6270490dbec7b214f5e63ea15e..d7a9a4e3dc0b052385dd3532d4a7ba1818c2139c 100644 (file)
@@ -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);
        }