diff options
| author | Karel Zak <kzak@redhat.com> | 2021-06-22 11:50:06 +0200 |
|---|---|---|
| committer | Karel Zak <kzak@redhat.com> | 2021-06-22 11:50:06 +0200 |
| commit | 94a5b2e84fba0545ba5485c04b671185895584ce (patch) | |
| tree | 9bb82888c7a9f33b27e38eee0963c2bd01539b88 /disk-utils/cfdisk.c | |
| parent | 3e5e56eb0ad620adfd1c26e1a9b3a09a59154165 (diff) | |
| download | util-linux-94a5b2e84fba0545ba5485c04b671185895584ce.tar.gz | |
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 <kzak@redhat.com>
Diffstat (limited to 'disk-utils/cfdisk.c')
| -rw-r--r-- | disk-utils/cfdisk.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c index b8891316eb..d7a9a4e3dc 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); } |
