misc: improve string to number conversions

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2021-06-24 16:42:53 +02:00
parent 9fc0f69c25
commit 1d5c14ae1a
4 changed files with 14 additions and 16 deletions

View 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[])

View 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);

View 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;
}

View 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;