]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
misc: improve string to number conversions
authorKarel Zak <kzak@redhat.com>
Thu, 24 Jun 2021 14:42:53 +0000 (16:42 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 24 Jun 2021 14:42:53 +0000 (16:42 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/fsck.c
sys-utils/eject.c
sys-utils/lscpu-cputype.c
text-utils/pg.c

index b9075bada62525c3f668104570caba64e5340575..8d92ada6e57bc54e09b90c9ddd7666b113e74bed 100644 (file)
@@ -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[])
index d534b61b6d19a39dc9dae8748b11e91474e88b43..5cd0beab2a94597a0431dc116ef3c279a93cb505 100644 (file)
@@ -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);
index db0eb6a98cf36ba0655be6491d879c70816ccf7e..795a4acf5d52dfa61871177a7e9a7f61513bdc0f 100644 (file)
@@ -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;
                                }
 
index 9da0070c513c6ad74631e5595ac990e0ac0304f4..d50e2ba8a54e5e1557f8deacae70af8802ec5717 100644 (file)
@@ -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;