We have macros for both positive and negative string matching.
Therefore there is no need to use !STREQ or !STRNEQ. At the same
time as we are dropping this, new syntax-check rule is
introduced to make sure we won't introduce it again.
Signed-off-by: Ishmanpreet Kaur Khera <khera.ishman@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
halt="avoid using 'pthread_create', use 'virThreadCreate' instead" \
$(_sc_search_regexp)
+sc_prohibit_not_streq:
+ @prohibit='! *STREQ *\(.*\)' \
+ halt='Use STRNEQ instead of !STREQ' \
+ $(_sc_search_regexp)
+
+sc_prohibit_not_strneq:
+ @prohibit='! *STRNEQ *\(.*\)' \
+ halt='Use STREQ instead of !STRNEQ' \
+ $(_sc_search_regexp)
+
# We don't use this feature of maint.mk.
prev_version_file = /dev/null
exclude_file_name_regexp--sc_prohibit_pthread_create = \
^(cfg\.mk|src/util/virthread\.c|tests/.*)$$
+
+exclude_file_name_regexp--sc_prohibit_not_streq = \
+ ^tests/.*\.[ch]$$
+
+exclude_file_name_regexp--sc_prohibit_not_strneq = \
+ ^tests/.*\.[ch]$$
if (conn->uri->server)
return VIR_DRV_OPEN_DECLINED;
- if (!STREQ_NULLABLE(conn->uri->path, "/system")) {
+ if (STRNEQ_NULLABLE(conn->uri->path, "/system")) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unexpected bhyve URI path '%s', try bhyve:///system"),
conn->uri->path);
if (!(def = virNetworkDefParseXML(ctxt)))
goto error;
- if (!STREQ(name, def->name)) {
+ if (STRNEQ(name, def->name)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Network config filename '%s'"
" does not match network name '%s'"),
if (!(def = virNetworkDefParseFile(configFile)))
goto error;
- if (!STREQ(name, def->name)) {
+ if (STRNEQ(name, def->name)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Network config filename '%s'"
" does not match network name '%s'"),
nwfilter = virNWFilterObjFindByUUID(nwfilters, def->uuid);
if (nwfilter) {
- if (!STREQ(def->name, nwfilter->def->name)) {
+ if (STRNEQ(def->name, nwfilter->def->name)) {
virReportError(VIR_ERR_OPERATION_FAILED,
_("filter with same UUID but different name "
"('%s') already exists"),
/* should never occur to step on a NULL here */
return true;
}
- if (!STREQ(virNWFilterVarValueGetNthValue(tmp, cie->curValue),
+ if (STRNEQ(virNWFilterVarValueGetNthValue(tmp, cie->curValue),
virNWFilterVarValueGetNthValue(tmp, i))) {
isSame = false;
break;
if (!(def = virStoragePoolDefParseXML(ctxt)))
goto error;
- if (!STREQ(name, def->name)) {
+ if (STRNEQ(name, def->name)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Storage pool state file '%s' does not match "
"pool name '%s'"),
off_t offset ATTRIBUTE_UNUSED,
struct fuse_file_info *fi ATTRIBUTE_UNUSED)
{
- if (!STREQ(path, "/"))
+ if (STRNEQ(path, "/"))
return -ENOENT;
filler(buf, ".", NULL, 0);
static int lxcProcOpen(const char *path ATTRIBUTE_UNUSED,
struct fuse_file_info *fi ATTRIBUTE_UNUSED)
{
- if (!STREQ(path, fuse_meminfo_path))
+ if (STRNEQ(path, fuse_meminfo_path))
return -ENOENT;
if ((fi->flags & 3) != O_RDONLY)
cur = vmdef->fss[pos];
/* We only allow updating the quota */
- if (!STREQ(cur->src, fs->src)
+ if (STRNEQ(cur->src, fs->src)
|| cur->type != fs->type
|| cur->accessmode != fs->accessmode
|| cur->wrpolicy != fs->wrpolicy
if (transp)
*transp++ = 0;
- if (!STREQ(uri->scheme, scheme)) {
+ if (STRNEQ(uri->scheme, scheme)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid transport/scheme '%s'"), uri->scheme);
goto error;
virDomainDiskDefPtr disk = def->disks[i];
if (disk->src->driverName != NULL &&
- !STREQ(disk->src->driverName, "qemu")) {
+ STRNEQ(disk->src->driverName, "qemu")) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unsupported driver name '%s' for disk '%s'"),
disk->src->driverName, disk->src->path);
if (VIR_STRDUP(model, tokens[i]) < 0)
goto cleanup;
- if (!STREQ(model, "qemu32") && !STREQ(model, "qemu64")) {
+ if (STRNEQ(model, "qemu32") && STRNEQ(model, "qemu64")) {
if (!(cpu = qemuInitGuestCPU(dom)))
goto cleanup;
if (!STRPREFIX(def->os.machine, "pc-0.") &&
!STRPREFIX(def->os.machine, "pc-1.") &&
!STRPREFIX(def->os.machine, "pc-i440") &&
- !STREQ(def->os.machine, "pc") &&
+ STRNEQ(def->os.machine, "pc") &&
!STRPREFIX(def->os.machine, "rhel"))
break;
addPCIRoot = true;
const char *driverName = virDomainDiskGetDriver(disk);
const char *src = virDomainDiskGetSource(disk);
- if (driverName && !STREQ(driverName, "qemu")) {
+ if (driverName && STRNEQ(driverName, "qemu")) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unsupported driver name '%s' for disk '%s'"),
driverName, src);
virSecurityManagerStackAddNested(virSecurityManagerPtr stack,
virSecurityManagerPtr nested)
{
- if (!STREQ("stack", stack->drv->name))
+ if (STRNEQ("stack", stack->drv->name))
return -1;
return virSecurityStackAddNested(stack, nested);
}
if (secdef == NULL)
return 0;
- if (!STREQ(SECURITY_SELINUX_NAME, secdef->model)) {
+ if (STRNEQ(SECURITY_SELINUX_NAME, secdef->model)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("security label driver mismatch: "
"'%s' model configured for domain, but "
return 0;
VIR_DEBUG("label=%s", secdef->label);
- if (!STREQ(SECURITY_SELINUX_NAME, secdef->model)) {
+ if (STRNEQ(SECURITY_SELINUX_NAME, secdef->model)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("security label driver mismatch: "
"'%s' model configured for domain, but "
return 0;
VIR_DEBUG("label=%s", secdef->label);
- if (!STREQ(SECURITY_SELINUX_NAME, secdef->model)) {
+ if (STRNEQ(SECURITY_SELINUX_NAME, secdef->model)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("security label driver mismatch: "
"'%s' model configured for domain, but "
if (!secdef || !secdef->label)
return 0;
- if (!STREQ(SECURITY_SELINUX_NAME, secdef->model)) {
+ if (STRNEQ(SECURITY_SELINUX_NAME, secdef->model)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("security label driver mismatch: "
"'%s' model configured for domain, but "
if (!secdef || !secdef->label)
return 0;
- if (!STREQ(SECURITY_SELINUX_NAME, secdef->model)) {
+ if (STRNEQ(SECURITY_SELINUX_NAME, secdef->model)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("security label driver mismatch: "
"'%s' model configured for domain, but "
if (!secdef || !secdef->label)
return 0;
- if (!STREQ(SECURITY_SELINUX_NAME, secdef->model)) {
+ if (STRNEQ(SECURITY_SELINUX_NAME, secdef->model)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("security label driver mismatch: "
"'%s' model configured for domain, but "
* (lvs outputs "[$lvname_vorigin] for field "origin" if the
* lv is created with "--virtualsize").
*/
- if (groups[1] && !STREQ(groups[1], "") && (groups[1][0] != '[')) {
+ if (groups[1] && STRNEQ(groups[1], "") && (groups[1][0] != '[')) {
if (VIR_ALLOC(vol->target.backingStore) < 0)
goto cleanup;
if (len < suffixlen)
return 0;
- if (!STREQ(str + len - suffixlen, suffix))
+ if (STRNEQ(str + len - suffixlen, suffix))
return 0;
str[len-suffixlen] = '\0';
goto cleanup;
if (error.code == VIR_ERR_ERROR &&
- !STREQ_NULLABLE("org.freedesktop.machine1.NoSuchMachine",
+ STRNEQ_NULLABLE("org.freedesktop.machine1.NoSuchMachine",
error.str1)) {
virReportErrorObject(&error);
goto cleanup;
return VIR_DRV_OPEN_DECLINED;
/* From this point on, the connection is for us. */
- if (!STREQ_NULLABLE(conn->uri->path, "/system")) {
+ if (STRNEQ_NULLABLE(conn->uri->path, "/system")) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unexpected Virtuozzo URI path '%s', try vz:///system"),
conn->uri->path);
}
} else {
if (def->os.nBootDevs != 0 ||
- !STREQ_NULLABLE(def->os.init, "/sbin/init") ||
+ STRNEQ_NULLABLE(def->os.init, "/sbin/init") ||
(def->os.initargv != NULL && def->os.initargv[0] != NULL)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
if (autonode) {
const char *val = (autonode->u.s.car->kind == SEXPR_VALUE
? autonode->u.s.car->u.value : NULL);
- if (!val || (!STREQ(val, "ignore") && !STREQ(val, "start"))) {
+ if (!val || (STRNEQ(val, "ignore") && STRNEQ(val, "start"))) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("unexpected value from on_xend_start"));
goto error;
/* Only xend <= 3.0.2 wants cdrom config here */
if (xendConfigVersion != XEND_CONFIG_VERSION_3_0_2)
break;
- if (!STREQ(def->disks[i]->dst, "hdc") || !src)
+ if (STRNEQ(def->disks[i]->dst, "hdc") || !src)
break;
virBufferEscapeSexpr(&buf, "(cdrom '%s')", src);
virCommandFree(cmd);
cmd = NULL;
- if (!STREQ(outactual, outexpect)) {
+ if (STRNEQ(outactual, outexpect)) {
virtTestDifference(stderr, outexpect, outactual);
goto cleanup;
}
if (!jointactual)
goto cleanup;
- if (!STREQ(outactual, outexpect)) {
+ if (STRNEQ(outactual, outexpect)) {
virtTestDifference(stderr, outexpect, outactual);
goto cleanup;
}
- if (!STREQ(erractual, errexpect)) {
+ if (STRNEQ(erractual, errexpect)) {
virtTestDifference(stderr, errexpect, erractual);
goto cleanup;
}
- if (!STREQ(jointactual, jointexpect)) {
+ if (STRNEQ(jointactual, jointexpect)) {
virtTestDifference(stderr, jointexpect, jointactual);
goto cleanup;
}
goto cleanup;
}
- if (!STREQ(outactual, outexpect)) {
+ if (STRNEQ(outactual, outexpect)) {
virtTestDifference(stderr, outexpect, outactual);
goto cleanup;
}
return -1;
}
}
- if (!STREQ_NULLABLE(files[i].context, ctx)) {
+ if (STRNEQ_NULLABLE(files[i].context, ctx)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"File %s context '%s' did not match epected '%s'",
files[i].file, ctx, files[i].context);
if (data->expect) {
if (!actual ||
- !STREQ(actual, data->expect)) {
+ STRNEQ(actual, data->expect)) {
VIR_WARN("Expected value '%s' for '%s' '%s' '%s', but got '%s'",
data->expect, data->hostname,
data->service, data->credname,
if (!str)
goto error;
- if (!STREQ(str, ""))
+ if (STRNEQ(str, ""))
goto error;
VIR_FREE(str);
if (!str)
goto error;
- if (!STREQ(str, "0"))
+ if (STRNEQ(str, "0"))
goto error;
VIR_FREE(str);
if (!str)
goto error;
- if (!STREQ(str, "0,4-5"))
+ if (STRNEQ(str, "0,4-5"))
goto error;
VIR_FREE(str);
if (!str)
goto error;
- if (!STREQ(str, "0,4-6"))
+ if (STRNEQ(str, "0,4-6"))
goto error;
VIR_FREE(str);
if (!str)
goto error;
- if (!STREQ(str, "0,4-6,13-16"))
+ if (STRNEQ(str, "0,4-6,13-16"))
goto error;
VIR_FREE(str);
if (!str)
goto error;
- if (!STREQ(str, "0,4-6,13-16,62-63"))
+ if (STRNEQ(str, "0,4-6,13-16,62-63"))
goto error;
}
for (i = 0; i < EXPECTED_NCPUS; i++) {
- if (!STREQ(params[i].field, VIR_DOMAIN_CPU_STATS_CPUTIME)) {
+ if (STRNEQ(params[i].field, VIR_DOMAIN_CPU_STATS_CPUTIME)) {
fprintf(stderr,
"Wrong parameter name value from virCgroupGetPercpuStats at %zu (is: %s)\n",
i, params[i].field);
VIR_DEBUG("Missing Value 'Foo.three'");
goto cleanup;
}
- if (!STREQ(virKeyFileGetValueString(kf, "Foo", "one"),
+ if (STRNEQ(virKeyFileGetValueString(kf, "Foo", "one"),
"The first entry is here")) {
VIR_DEBUG("Wrong value for 'Foo.one'");
goto cleanup;
}
- if (!STREQ(virKeyFileGetValueString(kf, "Foo", "two"),
+ if (STRNEQ(virKeyFileGetValueString(kf, "Foo", "two"),
"The second entry")) {
VIR_DEBUG("Wrong value for 'Foo.one'");
goto cleanup;
}
- if (!STREQ(virKeyFileGetValueString(kf, "Foo", "three"),
+ if (STRNEQ(virKeyFileGetValueString(kf, "Foo", "three"),
"The third entry")) {
VIR_DEBUG("Wrong value for 'Foo.one'");
goto cleanup;
VIR_DEBUG("Missing Value 'Bar.one'");
goto cleanup;
}
- if (!STREQ(virKeyFileGetValueString(kf, "Bar", "one"),
+ if (STRNEQ(virKeyFileGetValueString(kf, "Bar", "one"),
"The first entry in second group")) {
VIR_DEBUG("Wrong value for 'Bar.one'");
goto cleanup;
}
buf[rv] = '\0';
- if (!STREQ(buf, data->expectOut)) {
+ if (STRNEQ(buf, data->expectOut)) {
virtTestDifference(stderr, data->expectOut, buf);
goto cleanup;
}
goto cleanup;
continue;
}
- if (!STREQLEN(strings[i], "bar", 3))
+ if (STRNEQLEN(strings[i], "bar", 3))
goto cleanup;
if (strings[i][3] != l++)
goto cleanup;
if (!(uri = virURIParse(data->uri)))
goto cleanup;
- if (!STREQ(uri->scheme, data->scheme)) {
+ if (STRNEQ(uri->scheme, data->scheme)) {
VIR_DEBUG("Expected scheme '%s', actual '%s'",
data->scheme, uri->scheme);
goto cleanup;
}
- if (!STREQ(uri->server, data->server)) {
+ if (STRNEQ(uri->server, data->server)) {
VIR_DEBUG("Expected server '%s', actual '%s'",
data->server, uri->server);
goto cleanup;
goto cleanup;
}
- if (!STREQ_NULLABLE(uri->path, data->path)) {
+ if (STRNEQ_NULLABLE(uri->path, data->path)) {
VIR_DEBUG("Expected path '%s', actual '%s'",
data->path, uri->path);
goto cleanup;
}
- if (!STREQ_NULLABLE(uri->query, data->query)) {
+ if (STRNEQ_NULLABLE(uri->query, data->query)) {
VIR_DEBUG("Expected query '%s', actual '%s'",
data->query, uri->query);
goto cleanup;
}
- if (!STREQ_NULLABLE(uri->fragment, data->fragment)) {
+ if (STRNEQ_NULLABLE(uri->fragment, data->fragment)) {
VIR_DEBUG("Expected fragment '%s', actual '%s'",
data->fragment, uri->fragment);
goto cleanup;
}
for (i = 0; data->params && data->params[i].name && i < uri->paramsCount; i++) {
- if (!STREQ_NULLABLE(data->params[i].name, uri->params[i].name)) {
+ if (STRNEQ_NULLABLE(data->params[i].name, uri->params[i].name)) {
VIR_DEBUG("Expected param name %zu '%s', actual '%s'",
i, data->params[i].name, uri->params[i].name);
goto cleanup;
}
- if (!STREQ_NULLABLE(data->params[i].value, uri->params[i].value)) {
+ if (STRNEQ_NULLABLE(data->params[i].value, uri->params[i].value)) {
VIR_DEBUG("Expected param value %zu '%s', actual '%s'",
i, data->params[i].value, uri->params[i].value);
goto cleanup;
if (!(uristr = virURIFormat(uri)))
goto cleanup;
- if (!STREQ(uristr, data->uri_out)) {
+ if (STRNEQ(uristr, data->uri_out)) {
VIR_DEBUG("URI did not roundtrip, expect '%s', actual '%s'",
data->uri_out, uristr);
goto cleanup;