irqbalance: use endptr to check whether the input parameter is empty

Signed-off-by: Liu Chao <liuchao173@huawei.com>
This commit is contained in:
Liu Chao 2022-07-18 19:19:31 +08:00
parent 167580790c
commit d48eaf61c2

View file

@ -124,6 +124,7 @@ static void parse_command_line(int argc, char **argv)
int opt;
int longind;
unsigned long val;
char *endptr;
while ((opt = getopt_long(argc, argv,
"odfjVi:p:s:c:l:m:t:e:",
@ -139,8 +140,8 @@ static void parse_command_line(int argc, char **argv)
exit(1);
break;
case 'c':
deepest_cache = strtoul(optarg, NULL, 10);
if (deepest_cache == ULONG_MAX || deepest_cache < 1) {
deepest_cache = strtoul(optarg, &endptr, 10);
if (optarg == endptr || deepest_cache == ULONG_MAX || deepest_cache < 1) {
usage();
exit(1);
}
@ -153,8 +154,8 @@ static void parse_command_line(int argc, char **argv)
foreground_mode=1;
break;
case 'i':
val = strtoull(optarg, NULL, 10);
if (val == ULONG_MAX) {
val = strtoull(optarg, &endptr, 10);
if (optarg == endptr || val == ULONG_MAX) {
usage();
exit(1);
}
@ -171,8 +172,8 @@ static void parse_command_line(int argc, char **argv)
if (!strncmp(optarg, "off", strlen(optarg)))
power_thresh = ULONG_MAX;
else {
power_thresh = strtoull(optarg, NULL, 10);
if (power_thresh == ULONG_MAX) {
power_thresh = strtoull(optarg, &endptr, 10);
if (optarg == endptr || power_thresh == ULONG_MAX) {
usage();
exit(1);
}
@ -189,14 +190,18 @@ static void parse_command_line(int argc, char **argv)
foreground_mode=1;
break;
case 't':
sleep_interval = strtol(optarg, NULL, 10);
if (sleep_interval < 1) {
sleep_interval = strtol(optarg, &endptr, 10);
if (optarg == endptr || sleep_interval < 1) {
usage();
exit(1);
}
break;
case 'e':
migrate_ratio = strtoul(optarg, NULL, 10);
migrate_ratio = strtoul(optarg, &endptr, 10);
if (optarg == endptr) {
usage();
exit(1);
}
break;
}
}