Always perform == or != operation on cmp function result

Although not required to address bad code generation in
some versions of gcc 9 and 10, a coding style that requires
explicit comparison of the result to zero before use is
both clearer and would have avoided the generation of bad
code.

This change converts all use of cmp function usage from

```
    if (strcmp(a, b) || !strcmp(c, d)) ...
```

to

```
    if (strcmp(a, b) != 0 || strcmp(c, d)) == 0
```

for all C library cmp functions and related:

 - strcmp(), strncmp()
 - strcasecmp(), strncasecmp()
 - stricmp(), strnicmp()
 - memcmp()

Change-Id: Ic60c15e1e3a07e4faaf10648eefe3adae2543188
This commit is contained in:
Nicolas Williams
2021-11-14 23:52:50 -06:00
committed by Jeffrey Altman
parent 02200d55ea
commit 5f63215d0d
46 changed files with 119 additions and 116 deletions

View File

@@ -163,8 +163,8 @@ int k5dcesession(luid, pname, tgt, ppag, tflags)
/*
* (but root has the ffffffff which we are not interested in)
*/
if (!strncmp(direntp->d_name,"dcecred_",8)
&& (strlen(direntp->d_name) == 16)) {
if (strncmp(direntp->d_name,"dcecred_",8) == 0 &&
(strlen(direntp->d_name) == 16)) {
/* looks like a cache name, lets do the stat, etc */
@@ -246,7 +246,7 @@ int k5dcematch(luid, pname, ccname, sizep, tgt)
/* DEEDEBUG2("k5dcematch called: cache=%s\n",ccname+38); */
if (!strncmp(ccname,"FILE:",5)) {
if (strncmp(ccname,"FILE:",5) == 0) {
strcpy(ccdata,ccname+5);
strcat(ccdata,".data");
@@ -343,7 +343,7 @@ int k5dcegettgt(pcache, ccname, pname, tgt)
DEEDEBUG2("Unparsed to \"%s\"\n", kusername);
DEEDEBUG2("pname is \"%s\"\n", pname);
if (strcmp(kusername, pname)) {
if (strcmp(kusername, pname) != 0) {
DEEDEBUG("Principals not equal\n");
goto return1;
}
@@ -574,7 +574,7 @@ int k5dcecreate(luid, luser, pname, krbtgt)
}
if (!strcmp(urealm,defrealm)) {
if (strcmp(urealm,defrealm) == 0) {
strcpy(username,pname);
} else {
strcpy(username,"/.../");

View File

@@ -277,7 +277,7 @@ proto (int sock, const char *hostname, const char *svc,
}
krb5_data_free (&data);
return(strcmp(message, "ok"));
return strcmp(message, "ok") != 0;
}
static int