10000 Standardize treatment of strcmp() return value · postgrespro/postgres@037a827 · GitHub
[go: up one dir, main page]

Skip to content

Commit 037a827

Browse files
committed
Standardize treatment of strcmp() return value
Always compare the return value to 0, don't use cute tricks like if (!strcmp(...)).
1 parent d383c23 commit 037a827

File tree

27 files changed

+85
-86
lines changed

27 files changed

+85
-86
lines changed

contrib/fuzzystrmatch/dmetaphone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ StringAt(metastring *s, int start, int length,...)
364364
if (*test && (strncmp(pos, test, length) == 0))
365365
return 1;
366366
}
367-
while (strcmp(test, ""));
367+
while (strcmp(test, "") != 0);
368368

369369
va_end(ap);
370370

contrib/isn/isn.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -365,19 +365,19 @@ ean2isn(ean13 ean, bool errorOK, ean13 *result, enum isn_type accept)
365365
*--aux = '0'; /* fill the remaining EAN13 with '0' */
366366

367367
/* find out the data type: */
368-
if (!strncmp("978", buf, 3))
368+
if (strncmp("978", buf, 3) == 0)
369369
{ /* ISBN */
370370
type = ISBN;
371371
}
372-
else if (!strncmp("977", buf, 3))
372+
else if (strncmp("977", buf, 3) == 0)
373373
{ /* ISSN */
374374
type = ISSN;
375375
}
376-
else if (!strncmp("9790", buf, 4))
376+
else if (strncmp("9790", buf, 4) == 0)
377377
{ /* ISMN */
378378
type = ISMN;
379379
}
380-
else if (!strncmp("979", buf, 3))
380+
else if (strncmp("979", buf, 3) == 0)
381381
{ /* ISBN-13 */
382382
type = ISBN;
383383
}
@@ -570,28 +570,28 @@ ean2string(ean13 ean, bool errorOK, char *result, bool shortType)
570570
}
571571

572572
/* find out what type of hyphenation is needed: */
573-
if (!strncmp("978-", result, search))
573+
if (strncmp("978-", result, search) == 0)
574574
{ /* ISBN -13 978-range */
575575
/* The string should be in this form: 978-??000000000-0" */
576576
type = ISBN;
577577
TABLE = ISBN_range;
578578
TABLE_index = ISBN_index;
579579
}
580-
else if (!strncmp("977-", result, search))
580+
else if (strncmp("977-", result, search) == 0)
581581
{ /* ISSN */
582582
/* The string should be in this form: 977-??000000000-0" */
583583
type = ISSN;
584584
TABLE = ISSN_range;
585585
TABLE_index = ISSN_index;
586586
}
587-
else if (!strncmp("979-0", result, search + 1))
587+
else if (strncmp("979-0", result, search + 1) == 0)
588588
{ /* ISMN */
589589
/* The string should be in this form: 979-0?000000000-0" */
590590
type = ISMN;
591591
TABLE = ISMN_range;
592592
TABLE_index = ISMN_index;
593593
}
594-
else if (!strncmp("979-", result, search))
594+
else if (strncmp("979-", result, search) == 0)
595595
{ /* ISBN-13 979-range */
596596
/* The string should be in this form: 979-??000000000-0" */
597597
type = ISBN;
@@ -813,13 +813,13 @@ string2ean(const char *str, bool errorOK, ean13 *result,
813813
/* now get the subtype of EAN13: */
814814
if (buf[3] == '0')
815815
type = UPC;
816-
else if (!strncmp("977", buf + 3, 3))
816+
else if (strncmp("977", buf + 3, 3) == 0)
817817
type = ISSN;
818-
else if (!strncmp("978", buf + 3, 3))
818+
else if (strncmp("978", buf + 3, 3) == 0)
819819
type = ISBN;
820-
else if (!strncmp("9790", buf + 3, 4))
820+
else if (strncmp("9790", buf + 3, 4) == 0)
821821
type = ISMN;
822-
else if (!strncmp("979", buf + 3, 3))
822+
else if (strncmp("979", buf + 3, 3) == 0)
823823
type = ISBN;
824824
if (accept != EAN13 && accept != ANY && type != accept)
825825
goto eanwrongtype;

contrib/pgbench/pgbench.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1579,7 +1579,7 @@ process_commands(char *buf)
15791579
{
15801580
if (pg_strcasecmp(my_commands->argv[2], "us") != 0 &&
15811581
pg_strcasecmp(my_commands->argv[2], "ms") != 0 &&
1582-
pg_strcasecmp(my_commands->argv[2], "s"))
1582+
pg_strcasecmp(my_commands->argv[2], "s") != 0)
15831583
{
15841584
fprintf(stderr, "%s: unknown time unit '%s' - must be us, ms or s\n",
15851585
my_commands->argv[0], my_commands->argv[2]);

contrib/pgcrypto/crypt-md5.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ px_crypt_md5(const char *pw, const char *salt, char *passwd, unsigned dstlen)
5555
sp = salt;
5656

5757
/* If it starts with the magic string, then skip that */
58-
if (!strncmp(sp, magic, strlen(magic)))
58+
if (strncmp(sp, magic, strlen(magic)) == 0)
5959
sp += strlen(magic);
6060

6161
/* It stops at the first '$', max 8 chars */

contrib/pgcrypto/internal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ px_find_cipher(const char *name, PX_Cipher **res)
603603
name = px_resolve_alias(int_aliases, name);
604604

605605
for (i = 0; int_ciphers[i].name; i++)
606-
if (!strcmp(int_ciphers[i].name, name))
606+
if (strcmp(int_ciphers[i].name, name) == 0)
607607
{
608608
c = int_ciphers[i].load();
609609
break;

contrib/pgcrypto/openssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ px_find_cipher(const char *name, PX_Cipher **res)
953953

954954
name = px_resolve_alias(ossl_aliases, name);
955955
for (i = ossl_cipher_types; i->name; i++)
956-
if (!strcmp(i->name, name))
956+
if (strcmp(i->name, name) == 0)
957957
break;
958958
if (i->name == NULL)
959959
return PXE_NO_CIPHER;

contrib/pgcrypto/px-crypt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ px_crypt(const char *psw, const char *salt, char *buf, unsigned len)
9696
{
9797
if (!c->id_len)
9898
break;
99-
if (!strncmp(salt, c->id, c->id_len))
99+
if (strncmp(salt, c->id, c->id_len) == 0)
100100
break;
101101
}
102102

contrib/pgcrypto/px.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ parse_cipher_name(char *full, char **cipher, char **pad)
360360
if (p2 != NULL)
361361
{
362362
*p2++ = 0;
363-
if (!strcmp(p, "pad"))
363+
if (strcmp(p, "pad") == 0)
364364
*pad = p2;
365365
else
366366
return PXE_BAD_OPTION;
@@ -405,9 +405,9 @@ px_find_combo(const char *name, PX_Combo **res)
405405

406406
if (s_pad != NULL)
407407
{
408-
if (!strcmp(s_pad, "pkcs"))
408+
if (strcmp(s_pad, "pkcs") == 0)
409409
cx->padding = 1;
410-
else if (!strcmp(s_pad, "none"))
410+
else if (strcmp(s_pad, "none") == 0)
411411
cx->padding = 0;
412412
else
413413
goto err1;

src/backend/libpq/auth.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,7 @@ pg_SSPI_recvauth(Port *port)
14641464
*/
14651465
if (port->hba->krb_realm && strlen(port->hba->krb_realm))
14661466
{
1467-
if (pg_strcasecmp(port->hba->krb_realm, domainname))
1467+
if (pg_strcasecmp(port->hba->krb_realm, domainname) != 0)
14681468
{
14691469
elog(DEBUG2,
14701470
"SSPI domain (%s) and configured domain (%s) don't match",

src/backend/utils/adt/formatting.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ index_seq_search(char *str, const KeyWord *kw, const int *index)
10121012

10131013
do
10141014
{
1015-
if (!strncmp(str, k->name, k->len))
1015+
if (strncmp(str, k->name, k->len) == 0)
10161016
return k;
10171017
k++;
10181018
if (!k->name)
@@ -1032,7 +1032,7 @@ suff_search(char *str, KeySuffix *suf, int type)
10321032
if (s->type != type)
10331033
continue;
10341034

1035-
if (!strncmp(str, s->name, s->len))
1035+
if (strncmp(str, s->name, s->len) == 0)
10361036
return s;
10371037
}
10381038
return NULL;

0 commit comments

Comments
 (0)
0