diff options
author | Michael Paquier | 2019-04-12 01:16:49 +0000 |
---|---|---|
committer | Michael Paquier | 2019-04-12 01:16:49 +0000 |
commit | d527fda6216780281b90f48820ae978c61c7905c (patch) | |
tree | 3563030ccc2a229701963fa6f13e6e12e5a1b78e | |
parent | 798070ec058fe75757587c9e9916cc35c623f427 (diff) |
Fix more strcmp() calls using boolean-like comparisons for result checks
Such calls can confuse the reader as strcmp() uses an integer as result.
The places patched here have been spotted by Thomas Munro, David Rowley
and myself.
Author: Michael Paquier
Reviewed-by: David Rowley
Discussion: https://postgr.es/m/[email protected]
-rw-r--r-- | contrib/spi/refint.c | 9 | ||||
-rw-r--r-- | src/backend/commands/lockcmds.c | 3 | ||||
-rw-r--r-- | src/backend/tsearch/spell.c | 8 | ||||
-rw-r--r-- | src/test/modules/test_rls_hooks/test_rls_hooks.c | 8 |
4 files changed, 16 insertions, 12 deletions
diff --git a/contrib/spi/refint.c b/contrib/spi/refint.c index f90f2bce0e..adf0490f85 100644 --- a/contrib/spi/refint.c +++ b/contrib/spi/refint.c @@ -473,9 +473,12 @@ check_foreign_key(PG_FUNCTION_ARGS) nv = SPI_getvalue(newtuple, tupdesc, fn); type = SPI_gettype(tupdesc, fn); - if ((strcmp(type, "text") && strcmp(type, "varchar") && - strcmp(type, "char") && strcmp(type, "bpchar") && - strcmp(type, "date") && strcmp(type, "timestamp")) == 0) + if (strcmp(type, "text") == 0 || + strcmp(type, "varchar") == 0 || + strcmp(type, "char") == 0 || + strcmp(type, "bpchar") == 0 || + strcmp(type, "date") == 0 || + strcmp(type, "timestamp") == 0) is_char_type = 1; #ifdef DEBUG_QUERY elog(DEBUG4, "check_foreign_key Debug value %s type %s %d", diff --git a/src/backend/commands/lockcmds.c b/src/backend/commands/lockcmds.c index df681e3234..97cf0bc4ad 100644 --- a/src/backend/commands/lockcmds.c +++ b/src/backend/commands/lockcmds.c @@ -219,7 +219,8 @@ LockViewRecurse_walker(Node *node, LockViewRecurse_context *context) * skipped. */ if (relid == context->viewoid && - (!strcmp(rte->eref->aliasname, "old") || !strcmp(rte->eref->aliasname, "new"))) + (strcmp(rte->eref->aliasname, "old") == 0 || + strcmp(rte->eref->aliasname, "new") == 0)) continue; /* Currently, we only allow plain tables or views to be locked. */ diff --git a/src/backend/tsearch/spell.c b/src/backend/tsearch/spell.c index eb39466b22..c715f06b8e 100644 --- a/src/backend/tsearch/spell.c +++ b/src/backend/tsearch/spell.c @@ -1749,8 +1749,8 @@ NISortDictionary(IspellDict *Conf) naffix = 0; for (i = 0; i < Conf->nspell; i++) { - if (i == 0 - || strcmp(Conf->Spell[i]->p.flag, Conf->Spell[i - 1]->p.flag)) + if (i == 0 || + strcmp(Conf->Spell[i]->p.flag, Conf->Spell[i - 1]->p.flag) != 0) naffix++; } @@ -1764,8 +1764,8 @@ NISortDictionary(IspellDict *Conf) curaffix = -1; for (i = 0; i < Conf->nspell; i++) { - if (i == 0 - || strcmp(Conf->Spell[i]->p.flag, Conf->AffixData[curaffix])) + if (i == 0 || + strcmp(Conf->Spell[i]->p.flag, Conf->AffixData[curaffix]) != 0) { curaffix++; Assert(curaffix < naffix); diff --git a/src/test/modules/test_rls_hooks/test_rls_hooks.c b/src/test/modules/test_rls_hooks/test_rls_hooks.c index 8bf8f764ac..10379bc59c 100644 --- a/src/test/modules/test_rls_hooks/test_rls_hooks.c +++ b/src/test/modules/test_rls_hooks/test_rls_hooks.c @@ -75,8 +75,8 @@ test_rls_hooks_permissive(CmdType cmdtype, Relation relation) ParseState *qual_pstate; RangeTblEntry *rte; - if (strcmp(RelationGetRelationName(relation), "rls_test_permissive") - && strcmp(RelationGetRelationName(relation), "rls_test_both")) + if (strcmp(RelationGetRelationName(relation), "rls_test_permissive") != 0 && + strcmp(RelationGetRelationName(relation), "rls_test_both") != 0) return NIL; qual_pstate = make_parsestate(NULL); @@ -140,8 +140,8 @@ test_rls_hooks_restrictive(CmdType cmdtype, Relation relation) RangeTblEntry *rte; - if (strcmp(RelationGetRelationName(relation), "rls_test_restrictive") - && strcmp(RelationGetRelationName(relation), "rls_test_both")) + if (strcmp(RelationGetRelationName(relation), "rls_test_restrictive") != 0 && + strcmp(RelationGetRelationName(relation), "rls_test_both") != 0) return NIL; qual_pstate = make_parsestate(NULL); |