Skip to content

Commit

Permalink
Fix incorrect return-value check for a scanf like function
Browse files Browse the repository at this point in the history
  • Loading branch information
gsnw-sebast authored and auerswal committed Jun 23, 2024
1 parent 118cdc5 commit 94de791
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/fping.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ int main(int argc, char **argv)
break;

case 't':
if (!sscanf(optparse_state.optarg, "%f", &opt_value_float))
if (sscanf(optparse_state.optarg, "%f", &opt_value_float) != 1)
usage(1);
if (opt_value_float < 0) {
usage(1);
Expand All @@ -631,12 +631,12 @@ int main(int argc, char **argv)
break;

case 'r':
if (!sscanf(optparse_state.optarg, "%u", &retry))
if (sscanf(optparse_state.optarg, "%u", &retry) != 1)
usage(1);
break;

case 'i':
if (!sscanf(optparse_state.optarg, "%f", &opt_value_float))
if (sscanf(optparse_state.optarg, "%f", &opt_value_float) != 1)
usage(1);
if (opt_value_float < 0) {
usage(1);
Expand All @@ -645,7 +645,7 @@ int main(int argc, char **argv)
break;

case 'p':
if (!sscanf(optparse_state.optarg, "%f", &opt_value_float))
if (sscanf(optparse_state.optarg, "%f", &opt_value_float) != 1)
usage(1);
if (opt_value_float < 0) {
usage(1);
Expand All @@ -670,7 +670,7 @@ int main(int argc, char **argv)
break;

case 'b':
if (!sscanf(optparse_state.optarg, "%u", &ping_data_size))
if (sscanf(optparse_state.optarg, "%u", &ping_data_size) != 1)
usage(1);

break;
Expand All @@ -687,7 +687,7 @@ int main(int argc, char **argv)
case 'Q':
verbose_flag = 0;
quiet_flag = 1;
if (!sscanf(optparse_state.optarg, "%f", &opt_value_float))
if (sscanf(optparse_state.optarg, "%f", &opt_value_float) != 1)
usage(1);
if (opt_value_float < 0) {
usage(1);
Expand Down Expand Up @@ -865,7 +865,7 @@ int main(int argc, char **argv)
break;

case 'O':
if (sscanf(optparse_state.optarg, "%i", &tos)) {
if (sscanf(optparse_state.optarg, "%i", &tos) == 1) {
if (socket4 >= 0) {
if (setsockopt(socket4, IPPROTO_IP, IP_TOS, &tos, sizeof(tos))) {
perror("setting type of service octet IP_TOS");
Expand Down

0 comments on commit 94de791

Please sign in to comment.