Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d527fda

Browse files
committed
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/20190411021946.GG2728@paquier.xyz
1 parent 798070e commit d527fda

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

contrib/spi/refint.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,12 @@ check_foreign_key(PG_FUNCTION_ARGS)
473473
nv = SPI_getvalue(newtuple, tupdesc, fn);
474474
type = SPI_gettype(tupdesc, fn);
475475

476-
if ((strcmp(type, "text") && strcmp(type, "varchar") &&
477-
strcmp(type, "char") && strcmp(type, "bpchar") &&
478-
strcmp(type, "date") && strcmp(type, "timestamp")) == 0)
476+
if (strcmp(type, "text") == 0 ||
477+
strcmp(type, "varchar") == 0 ||
478+
strcmp(type, "char") == 0 ||
479+
strcmp(type, "bpchar") == 0 ||
480+
strcmp(type, "date") == 0 ||
481+
strcmp(type, "timestamp") == 0)
479482
is_char_type = 1;
480483
#ifdef DEBUG_QUERY
481484
elog(DEBUG4, "check_foreign_key Debug value %s type %s %d",

src/backend/commands/lockcmds.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ LockViewRecurse_walker(Node *node, LockViewRecurse_context *context)
219219
* skipped.
220220
*/
221221
if (relid == context->viewoid &&
222-
(!strcmp(rte->eref->aliasname, "old") || !strcmp(rte->eref->aliasname, "new")))
222+
(strcmp(rte->eref->aliasname, "old") == 0 ||
223+
strcmp(rte->eref->aliasname, "new") == 0))
223224
continue;
224225

225226
/* Currently, we only allow plain tables or views to be locked. */

src/backend/tsearch/spell.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -1749,8 +1749,8 @@ NISortDictionary(IspellDict *Conf)
17491749
naffix = 0;
17501750
for (i = 0; i < Conf->nspell; i++)
17511751
{
1752-
if (i == 0
1753-
|| strcmp(Conf->Spell[i]->p.flag, Conf->Spell[i - 1]->p.flag))
1752+
if (i == 0 ||
1753+
strcmp(Conf->Spell[i]->p.flag, Conf->Spell[i - 1]->p.flag) != 0)
17541754
naffix++;
17551755
}
17561756

@@ -1764,8 +1764,8 @@ NISortDictionary(IspellDict *Conf)
17641764
curaffix = -1;
17651765
for (i = 0; i < Conf->nspell; i++)
17661766
{
1767-
if (i == 0
1768-
|| strcmp(Conf->Spell[i]->p.flag, Conf->AffixData[curaffix]))
1767+
if (i == 0 ||
1768+
strcmp(Conf->Spell[i]->p.flag, Conf->AffixData[curaffix]) != 0)
17691769
{
17701770
curaffix++;
17711771
Assert(curaffix < naffix);

src/test/modules/test_rls_hooks/test_rls_hooks.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ test_rls_hooks_permissive(CmdType cmdtype, Relation relation)
7575
ParseState *qual_pstate;
7676
RangeTblEntry *rte;
7777

78-
if (strcmp(RelationGetRelationName(relation), "rls_test_permissive")
79-
&& strcmp(RelationGetRelationName(relation), "rls_test_both"))
78+
if (strcmp(RelationGetRelationName(relation), "rls_test_permissive") != 0 &&
79+
strcmp(RelationGetRelationName(relation), "rls_test_both") != 0)
8080
return NIL;
8181

8282
qual_pstate = make_parsestate(NULL);
@@ -140,8 +140,8 @@ test_rls_hooks_restrictive(CmdType cmdtype, Relation relation)
140140
RangeTblEntry *rte;
141141

142142

143-
if (strcmp(RelationGetRelationName(relation), "rls_test_restrictive")
144-
&& strcmp(RelationGetRelationName(relation), "rls_test_both"))
143+
if (strcmp(RelationGetRelationName(relation), "rls_test_restrictive") != 0 &&
144+
strcmp(RelationGetRelationName(relation), "rls_test_both") != 0)
145145
return NIL;
146146

147147
qual_pstate = make_parsestate(NULL);

0 commit comments

Comments
 (0)