Refactor string comparisons

Clean up use of strcmp/strncmp/strncasecmp for command line arguments.
Never use anything but `strcmp()` unless absolutely neccessary.

Partialy resolves ipmitool/ipmitool#104
This commit is contained in:
Jiang Junyu
2020-02-21 13:53:38 -08:00
committed by Alexander Amelkin
parent 9d5ea21df7
commit 6e037d6bfb
34 changed files with 563 additions and 570 deletions

View File

@@ -167,8 +167,8 @@ void ipmi_intf_print(struct ipmi_intf_support * intflist)
if (intflist) {
found = 0;
for (sup=intflist; sup->name; sup++) {
if (strncmp(sup->name, (*intf)->name, strlen(sup->name)) == 0 &&
strncmp(sup->name, (*intf)->name, strlen((*intf)->name)) == 0 &&
if (strcmp(sup->name, (*intf)->name) == 0 &&
strcmp(sup->name, (*intf)->name) == 0 &&
sup->supported == 1)
found = 1;
}
@@ -211,7 +211,7 @@ struct ipmi_intf * ipmi_intf_load(char * name)
intf++)
{
i = *intf;
if (strncmp(name, i->name, strlen(name)) == 0) {
if (strcmp(name, i->name) == 0) {
if (i->setup && (i->setup(i) < 0)) {
lprintf(LOG_ERR, "Unable to setup "
"interface %s", name);

View File

@@ -394,7 +394,7 @@ recv_response(struct ipmi_intf * intf, unsigned char *data, int len)
*pp = 0;
/* was it an error? */
if (strncmp(p, "ERR ", 4) == 0) {
if (strcmp(p, "ERR ") == 0) {
serial_write_line(intf, "\r\r\r\r");
sleep(1);
serial_flush(intf);

View File

@@ -133,7 +133,7 @@ scsiProbeNew(int *num_ami_devices, int *sg_nos)
}
if (sscanf(linebuf, "%s", vendor) == 1) {
if (strncmp(vendor, "AMI", strlen("AMI")) == 0) {
if (strcmp(vendor, "AMI") == 0) {
numdevfound++;
sg_nos[numdevfound - 1] = lineno;
if (numdevfound == inplen) {
@@ -249,7 +249,7 @@ IsG2Drive(int cd_desc)
return 1;
}
if (strncmp(szSignature, "$$$AMI$$$", strlen("$$$AMI$$$")) != 0) {
if (strcmp(szSignature, "$$$AMI$$$") != 0) {
lprintf(LOG_ERR,
"IsG2Drive:Signature mismatch when ID command sent");
return 1;