]> granicus.if.org Git - postgresql/commitdiff
Fix more strcmp() calls using boolean-like comparisons for result checks
authorMichael Paquier <michael@paquier.xyz>
Fri, 12 Apr 2019 01:16:49 +0000 (10:16 +0900)
committerMichael Paquier <michael@paquier.xyz>
Fri, 12 Apr 2019 01:16:49 +0000 (10:16 +0900)
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/20190411021946.GG2728@paquier.xyz

contrib/spi/refint.c
src/backend/commands/lockcmds.c
src/backend/tsearch/spell.c
src/test/modules/test_rls_hooks/test_rls_hooks.c

index f90f2bce0ea673997c20c7b424c9f66dfcc3249c..adf0490f8539b0fa7ac5016052b9761021c5e225 100644 (file)
@@ -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",
index df681e32341f002f7c096638dfe826aaed26805b..97cf0bc4add985f4b04c8b0866b0a8fa5d328f28 100644 (file)
@@ -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. */
index eb39466b228e4febf0d8314ca6cd7efd337f48e4..c715f06b8e25bdb5819189fb950d89640486dcb3 100644 (file)
@@ -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);
index 8bf8f764ac31a7016fb53c43052d74e8915e44c9..10379bc59c0ecae89fef85391d0bc63baa868966 100644 (file)
@@ -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);