mirror of
https://github.com/ipmitool/ipmitool.git
synced 2026-06-29 16:51:35 +00:00
Finalize refactoring of string comparisons
Unify the comparison idioms use. Always use `if(!strcmp())` for "if string equals" and `if(strcmp())` for "if string is not equal". Never use `== 0` and `!= 0` with `strcmp()`. Minor reformatting of the code immediately surrounding the refactored lines. Resolves ipmitool/ipmitool#104 Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
This commit is contained in:
committed by
Alexander Amelkin
parent
e3fc775d26
commit
956ae2b372
@@ -190,22 +190,22 @@ ipmi_cmd_run(struct ipmi_intf * intf, char * name, int argc, char ** argv)
|
||||
if (!name) {
|
||||
if (!cmd->func || !cmd->name)
|
||||
return -1;
|
||||
else if (strcmp(cmd->name, "default") == 0)
|
||||
|
||||
if (!strcmp(cmd->name, "default"))
|
||||
return cmd->func(intf, 0, NULL);
|
||||
else {
|
||||
lprintf(LOG_ERR, "No command provided!");
|
||||
ipmi_cmd_print(intf->cmdlist);
|
||||
return -1;
|
||||
}
|
||||
|
||||
lprintf(LOG_ERR, "No command provided!");
|
||||
ipmi_cmd_print(intf->cmdlist);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (cmd=intf->cmdlist; cmd->func; cmd++) {
|
||||
if (strcmp(name, cmd->name) == 0)
|
||||
if (!strcmp(name, cmd->name))
|
||||
break;
|
||||
}
|
||||
if (!cmd->func) {
|
||||
cmd = intf->cmdlist;
|
||||
if (strcmp(cmd->name, "default") == 0)
|
||||
if (!strcmp(cmd->name, "default"))
|
||||
return cmd->func(intf, argc+1, argv-1);
|
||||
|
||||
lprintf(LOG_ERR, "Invalid command: %s", name);
|
||||
@@ -380,10 +380,11 @@ ipmi_main(int argc, char ** argv,
|
||||
if (intflist) {
|
||||
found = 0;
|
||||
for (sup=intflist; sup->name; sup++) {
|
||||
if (strcmp(sup->name, intfname) == 0 &&
|
||||
strcmp(sup->name, intfname) == 0 &&
|
||||
sup->supported == 1)
|
||||
if (!strcmp(sup->name, intfname)
|
||||
&& sup->supported)
|
||||
{
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
lprintf(LOG_ERR, "Interface %s not supported", intfname);
|
||||
@@ -609,8 +610,9 @@ ipmi_main(int argc, char ** argv,
|
||||
lprintf(LOG_ERR, "%s: malloc failure", progname);
|
||||
goto out_free;
|
||||
}
|
||||
if (strcmp(oemtype, "list") == 0 ||
|
||||
strcmp(oemtype, "help") == 0) {
|
||||
if (!strcmp(oemtype, "list")
|
||||
|| !strcmp(oemtype, "help"))
|
||||
{
|
||||
ipmi_oem_print();
|
||||
rc = 0;
|
||||
goto out_free;
|
||||
@@ -777,8 +779,9 @@ ipmi_main(int argc, char ** argv,
|
||||
}
|
||||
|
||||
/* check for command before doing anything */
|
||||
if (argc-optind > 0 &&
|
||||
strcmp(argv[optind], "help") == 0) {
|
||||
if (argc-optind > 0
|
||||
&& !strcmp(argv[optind], "help"))
|
||||
{
|
||||
ipmi_cmd_print(cmdlist);
|
||||
rc = 0;
|
||||
goto out_free;
|
||||
@@ -823,11 +826,11 @@ ipmi_main(int argc, char ** argv,
|
||||
}
|
||||
|
||||
if (password && intfname) {
|
||||
if (strcmp(intfname, "lan") == 0 && strlen(password) > 16) {
|
||||
if (!strcmp(intfname, "lan") && strlen(password) > 16) {
|
||||
lprintf(LOG_ERR, "%s: password is longer than 16 bytes.", intfname);
|
||||
rc = -1;
|
||||
goto out_free;
|
||||
} else if (strcmp(intfname, "lanplus") == 0 && strlen(password) > 20) {
|
||||
} else if (!strcmp(intfname, "lanplus") && strlen(password) > 20) {
|
||||
lprintf(LOG_ERR, "%s: password is longer than 20 bytes.", intfname);
|
||||
rc = -1;
|
||||
goto out_free;
|
||||
|
||||
Reference in New Issue
Block a user