From 1d5c14ae1a6597807f214b2eb50c0eebad75ed24 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 24 Jun 2021 16:42:53 +0200 Subject: [PATCH] misc: improve string to number conversions Signed-off-by: Karel Zak --- disk-utils/fsck.c | 5 ++--- sys-utils/eject.c | 6 +++--- sys-utils/lscpu-cputype.c | 4 ++-- text-utils/pg.c | 15 +++++++-------- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/disk-utils/fsck.c b/disk-utils/fsck.c index b9075bada..8d92ada6e 100644 --- a/disk-utils/fsck.c +++ b/disk-utils/fsck.c @@ -1432,7 +1432,6 @@ static void parse_argv(int argc, char *argv[]) int opts_for_fsck = 0; struct sigaction sa; int report_stats_fd = -1; - uint64_t num; /* * Set up signal action @@ -1605,8 +1604,8 @@ static void parse_argv(int argc, char *argv[]) if (getenv("FSCK_FORCE_ALL_PARALLEL")) force_all_parallel++; - if (ul_strtou64(getenv("FSCK_MAX_INST"), &num, 10) == 0 && num <= INT_MAX) - max_running = num; + if (ul_strtos32(getenv("FSCK_MAX_INST"), &max_running, 10) != 0) + max_running = 0; } int main(int argc, char *argv[]) diff --git a/sys-utils/eject.c b/sys-utils/eject.c index d534b61b6..5cd0beab2 100644 --- a/sys-utils/eject.c +++ b/sys-utils/eject.c @@ -526,15 +526,15 @@ static int read_speed(const char *devname) /* find line "drive speed" and read the correct speed */ } else { if (strncmp(line, "drive speed:", 12) == 0) { - uint64_t n; + int n; fclose(f); str = line + 12; normalize_whitespace((unsigned char *) str); - if (ul_strtou64(str, &n, 10) == 0 && n <= INT_MAX) - return (int) n; + if (ul_strtos32(str, &n, 10) == 0) + return n; errx(EXIT_FAILURE, _("%s: failed to read speed"), _PATH_PROC_CDROMINFO); diff --git a/sys-utils/lscpu-cputype.c b/sys-utils/lscpu-cputype.c index db0eb6a98..795a4acf5 100644 --- a/sys-utils/lscpu-cputype.c +++ b/sys-utils/lscpu-cputype.c @@ -499,8 +499,8 @@ int lscpu_read_cpuinfo(struct lscpu_cxt *cxt) if (keynum >= 0) id = keynum; else { - uint64_t n; - if (ul_strtou64(value, &n, 10) == 0 && n <= INT_MAX) + uint32_t n; + if (ul_strtou32(value, &n, 10) == 0) id = n; } diff --git a/text-utils/pg.c b/text-utils/pg.c index 9da0070c5..d50e2ba8a 100644 --- a/text-utils/pg.c +++ b/text-utils/pg.c @@ -317,15 +317,14 @@ static void getwinsize(void) struct winsize winsz; int badioctl; #endif - char *p; - if (initialized == 0) { - if ((p = getenv("LINES")) != NULL && *p != '\0') - if ((envlines = atoi(p)) < 0) - envlines = 0; - if ((p = getenv("COLUMNS")) != NULL && *p != '\0') - if ((envcols = atoi(p)) < 0) - envcols = 0; + uint32_t tmp = 0; + + if (ul_strtou32(getenv("LINES"), &tmp, 10) == 0) + envlines = tmp; + if (ul_strtou32(getenv("COLUMNS"), &tmp, 10) == 0) + envcols = tmp; + /* terminfo values. */ if (tinfostat != 1 || columns == 0) defcols = 24;