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:

committed by
Jeffrey Altman

parent
02200d55ea
commit
5f63215d0d
@@ -471,7 +471,7 @@ dotype(unsigned char *buf, size_t len, char **argv, size_t *size)
|
||||
ret = sorted_types[i].encode(der + (sz - 1), sz, v, &sz);
|
||||
if (ret != 0)
|
||||
errx(1, "Encoding failed");
|
||||
if (memcmp(buf, der, sz))
|
||||
if (memcmp(buf, der, sz) != 0)
|
||||
errx(1, "Encoding did not round trip");
|
||||
free(der);
|
||||
}
|
||||
@@ -490,7 +490,7 @@ dotype(unsigned char *buf, size_t len, char **argv, size_t *size)
|
||||
ret = sorted_types[i].encode(der + (sz - 1), sz, vcpy, &sz);
|
||||
if (ret != 0)
|
||||
errx(1, "Encoding of copy failed");
|
||||
if (memcmp(buf, der, sz))
|
||||
if (memcmp(buf, der, sz) != 0)
|
||||
errx(1, "Encoding of copy did not round trip");
|
||||
free(der);
|
||||
}
|
||||
|
@@ -1945,7 +1945,7 @@ validate_object_set(IOSObjectSet *os)
|
||||
sort_object_set(os, cf, &objects, &nobjs);
|
||||
for (i = 0; i < nobjs; i++) {
|
||||
HEIM_TAILQ_FOREACH(of, objects[i]->objfields, objfields) {
|
||||
if (strcmp(cf->name, of->name))
|
||||
if (strcmp(cf->name, of->name) != 0)
|
||||
continue;
|
||||
if (!of->value)
|
||||
errx(1, "Value not specified for required UNIQUE field %s of object %s",
|
||||
@@ -1970,7 +1970,7 @@ validate_object_set(IOSObjectSet *os)
|
||||
int specified = 0;
|
||||
|
||||
HEIM_TAILQ_FOREACH(of, o->objfields, objfields) {
|
||||
if (strcmp(of->name, cf->name))
|
||||
if (strcmp(of->name, cf->name) != 0)
|
||||
continue;
|
||||
if (of->value)
|
||||
specified = 1;
|
||||
|
@@ -883,24 +883,24 @@ test_heim_oid_format_same(const char *str, const heim_oid *oid)
|
||||
printf("fail to print oid: %s\n", str);
|
||||
return 1;
|
||||
}
|
||||
ret = strcmp(p, str);
|
||||
if (ret) {
|
||||
|
||||
if (strcmp(p, str) != 0) {
|
||||
printf("oid %s != formated oid %s\n", str, p);
|
||||
free(p);
|
||||
return ret;
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = der_parse_heim_oid(p, " ", &o2);
|
||||
if (ret) {
|
||||
printf("failed to parse %s\n", p);
|
||||
free(p);
|
||||
return ret;
|
||||
return 1;
|
||||
}
|
||||
free(p);
|
||||
ret = der_heim_oid_cmp(&o2, oid);
|
||||
der_free_oid(&o2);
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static unsigned sha1_oid_tree[] = { 1, 3, 14, 3, 2, 26 };
|
||||
|
@@ -2367,7 +2367,7 @@ test_ios(void)
|
||||
s = print_Certificate(&c0, 0);
|
||||
if (!s)
|
||||
return 1;
|
||||
if (strcmp(s, cert_json))
|
||||
if (strcmp(s, cert_json) != 0)
|
||||
return 1;
|
||||
free(s);
|
||||
|
||||
@@ -2407,7 +2407,7 @@ test_ios(void)
|
||||
return 1;
|
||||
if (os.length != size || size != sizeof(encoded_sample))
|
||||
return 1;
|
||||
if (memcmp(os.data, encoded_sample, os.length))
|
||||
if (memcmp(os.data, encoded_sample, os.length) != 0)
|
||||
return 1;
|
||||
der_free_octet_string(&os);
|
||||
|
||||
@@ -2424,7 +2424,7 @@ test_ios(void)
|
||||
return 1;
|
||||
if (os.length != size || size != sizeof(encoded_sample))
|
||||
return 1;
|
||||
if (memcmp(os.data, encoded_sample, os.length))
|
||||
if (memcmp(os.data, encoded_sample, os.length) != 0)
|
||||
return 1;
|
||||
der_free_octet_string(&os);
|
||||
|
||||
@@ -2440,7 +2440,7 @@ test_ios(void)
|
||||
return 1;
|
||||
if (os.length != size || size != sizeof(encoded_sample))
|
||||
return 1;
|
||||
if (memcmp(os.data, encoded_sample, os.length))
|
||||
if (memcmp(os.data, encoded_sample, os.length) != 0)
|
||||
return 1;
|
||||
der_free_octet_string(&os);
|
||||
|
||||
|
@@ -650,7 +650,7 @@ _heim_der_set_sort(const void *a1, const void *a2)
|
||||
|
||||
ret = memcmp(s1->data, s2->data,
|
||||
s1->length < s2->length ? s1->length : s2->length);
|
||||
if(ret)
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
return (int)(s1->length - s2->length);
|
||||
}
|
||||
|
@@ -990,7 +990,7 @@ get_open_type_defn_fields(const Type *t,
|
||||
}
|
||||
/* Look for the type ID member identified in the previous loop */
|
||||
HEIM_TAILQ_FOREACH(m, t->members, members) {
|
||||
if (!m->type->subtype || strcmp(m->name, idmembername))
|
||||
if (!m->type->subtype || strcmp(m->name, idmembername) != 0)
|
||||
continue;
|
||||
if (m->type->constraint &&
|
||||
m->type->constraint->ctype == CT_TABLE_CONSTRAINT)
|
||||
@@ -1040,7 +1040,7 @@ define_open_type(int level, const char *newbasename, const char *name, const cha
|
||||
newbasename);
|
||||
for (i = 0; i < nobjs; i++) {
|
||||
HEIM_TAILQ_FOREACH(of, objects[i]->objfields, objfields) {
|
||||
if (strcmp(of->name, typeidfield->name))
|
||||
if (strcmp(of->name, typeidfield->name) != 0)
|
||||
continue;
|
||||
if (!of->value || !of->value->s)
|
||||
errx(1, "Unknown value in value field %s of object %s",
|
||||
@@ -1060,7 +1060,7 @@ define_open_type(int level, const char *newbasename, const char *name, const cha
|
||||
HEIM_TAILQ_FOREACH(of, objects[i]->objfields, objfields) {
|
||||
char *n = NULL;
|
||||
|
||||
if (strcmp(of->name, opentypefield->name))
|
||||
if (strcmp(of->name, opentypefield->name) != 0)
|
||||
continue;
|
||||
if (!of->type || (!of->type->symbol && of->type->type != TTag) ||
|
||||
of->type->tag.tagclass != ASN1_C_UNIV) {
|
||||
@@ -1631,7 +1631,8 @@ generate_type_header (const Symbol *s)
|
||||
t = s->type->symbol->type;
|
||||
}
|
||||
|
||||
if (t->type == TType && t->symbol && strcmp(t->symbol->name, "HEIM_ANY")) {
|
||||
if (t->type == TType && t->symbol &&
|
||||
strcmp(t->symbol->name, "HEIM_ANY") != 0) {
|
||||
/*
|
||||
* This type is ultimately an alias of an imported type, so we don't
|
||||
* know its outermost tag here.
|
||||
|
@@ -530,7 +530,8 @@ decode_type(const char *name, const Type *t, int optional, struct value *defval,
|
||||
(t->subtype->type == TSequence ||
|
||||
t->subtype->type == TSet))
|
||||
replace_tag = 1;
|
||||
else if (t->subtype->symbol && strcmp(t->subtype->symbol->name, "HEIM_ANY"))
|
||||
else if (t->subtype->symbol &&
|
||||
strcmp(t->subtype->symbol->name, "HEIM_ANY") != 0)
|
||||
replace_tag = 1;
|
||||
} else if (t->tag.tagenv == TE_IMPLICIT && prim && t->subtype->symbol)
|
||||
replace_tag = is_tagged_type(t->subtype->symbol->type);
|
||||
|
@@ -370,7 +370,7 @@ tlist_cmp(const struct tlist *tl, const struct tlist *ql)
|
||||
if (tl == ql)
|
||||
return 0;
|
||||
ret = strcmp(tl->header, ql->header);
|
||||
if (ret) return ret;
|
||||
if (ret != 0) return ret;
|
||||
|
||||
q = HEIM_TAILQ_FIRST(&ql->template);
|
||||
HEIM_TAILQ_FOREACH(t, &tl->template, members) {
|
||||
@@ -378,13 +378,13 @@ tlist_cmp(const struct tlist *tl, const struct tlist *ql)
|
||||
|
||||
if (t->ptr == NULL || q->ptr == NULL) {
|
||||
ret = strcmp(t->line, q->line);
|
||||
if (ret) return ret;
|
||||
if (ret != 0) return ret;
|
||||
} else {
|
||||
ret = strcmp(t->tt, q->tt);
|
||||
if (ret) return ret;
|
||||
if (ret != 0) return ret;
|
||||
|
||||
ret = strcmp(t->offset, q->offset);
|
||||
if (ret) return ret;
|
||||
if (ret != 0) return ret;
|
||||
|
||||
if ((ret = strcmp(t->ptr, q->ptr)) != 0 ||
|
||||
(ret = tlist_cmp_name(t->ptr, q->ptr)) != 0)
|
||||
|
Reference in New Issue
Block a user