Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit037a827

Browse files
committed
Standardize treatment of strcmp() return value
Always compare the return value to 0, don't use cute tricks likeif (!strcmp(...)).
1 parentd383c23 commit037a827

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
return1;
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-
elseif (!strncmp("977",buf,3))
372+
elseif (strncmp("977",buf,3)==0)
373373
{/* ISSN */
374374
type=ISSN;
375375
}
376-
elseif (!strncmp("9790",buf,4))
376+
elseif (strncmp("9790",buf,4)==0)
377377
{/* ISMN */
378378
type=ISMN;
379379
}
380-
elseif (!strncmp("979",buf,3))
380+
elseif (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-
elseif (!strncmp("977-",result,search))
580+
elseif (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-
elseif (!strncmp("979-0",result,search+1))
587+
elseif (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-
elseif (!strncmp("979-",result,search))
594+
elseif (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-
elseif (!strncmp("977",buf+3,3))
816+
elseif (strncmp("977",buf+3,3)==0)
817817
type=ISSN;
818-
elseif (!strncmp("978",buf+3,3))
818+
elseif (strncmp("978",buf+3,3)==0)
819819
type=ISBN;
820-
elseif (!strncmp("9790",buf+3,4))
820+
elseif (strncmp("9790",buf+3,4)==0)
821821
type=ISMN;
822-
elseif (!strncmp("979",buf+3,3))
822+
elseif (strncmp("979",buf+3,3)==0)
823823
type=ISBN;
824824
if (accept!=EAN13&&accept!=ANY&&type!=accept)
825825
gotoeanwrongtype;

‎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
returnPXE_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
returnPXE_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-
elseif (!strcmp(s_pad,"none"))
410+
elseif (strcmp(s_pad,"none")==0)
411411
cx->padding=0;
412412
else
413413
gotoerr1;

‎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
returnk;
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
returns;
10371037
}
10381038
returnNULL;

‎src/bin/initdb/initdb.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ setup_config(void)
10981098

10991099
conflines=replace_token(conflines,
11001100
"@authcomment@",
1101-
strcmp(authmethod,"trust") ?"" :AUTHTRUST_WARNING);
1101+
strcmp(authmethod,"trust")!=0?"" :AUTHTRUST_WARNING);
11021102

11031103
/* Replace username for replication */
11041104
conflines=replace_token(conflines,
@@ -2667,16 +2667,16 @@ main(int argc, char *argv[])
26672667
authmethod="trust";
26682668
}
26692669

2670-
if (strcmp(authmethod,"md5")&&
2671-
strcmp(authmethod,"peer")&&
2672-
strcmp(authmethod,"ident")&&
2673-
strcmp(authmethod,"trust")&&
2670+
if (strcmp(authmethod,"md5")!=0&&
2671+
strcmp(authmethod,"peer")!=0&&
2672+
strcmp(authmethod,"ident")!=0&&
2673+
strcmp(authmethod,"trust")!=0&&
26742674
#ifdefUSE_PAM
2675-
strcmp(authmethod,"pam")&&
2676-
strncmp(authmethod,"pam ",4)&&/* pam with space = param */
2675+
strcmp(authmethod,"pam")!=0&&
2676+
strncmp(authmethod,"pam ",4)!=0&&/* pam with space = param */
26772677
#endif
2678-
strcmp(authmethod,"crypt")&&
2679-
strcmp(authmethod,"password")
2678+
strcmp(authmethod,"crypt")!=0&&
2679+
strcmp(authmethod,"password")!=0
26802680
)
26812681

26822682
/*
@@ -2689,9 +2689,9 @@ main(int argc, char *argv[])
26892689
exit(1);
26902690
}
26912691

2692-
if ((!strcmp(authmethod,"md5")||
2693-
!strcmp(authmethod,"crypt")||
2694-
!strcmp(authmethod,"password"))&&
2692+
if ((strcmp(authmethod,"md5")==0||
2693+
strcmp(authmethod,"crypt")==0||
2694+
strcmp(authmethod,"password")==0)&&
26952695
!(pwprompt||pwfilename))
26962696
{
26972697
fprintf(stderr,_("%s: must specify a password for the superuser to enable %s authentication\n"),progname,authmethod);

‎src/bin/pg_basebackup/pg_receivexlog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ FindStreamingStart(XLogRecPtr currentpos, uint32 currenttimeline)
126126
log,
127127
seg;
128128

129-
if (!strcmp(dirent->d_name,".")||!strcmp(dirent->d_name,".."))
129+
if (strcmp(dirent->d_name,".")==0||strcmp(dirent->d_name,"..")==0)
130130
continue;
131131

132132
/* xlog files are always 24 characters */

‎src/bin/pg_ctl/pg_ctl.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ pgwin32_CommandLine(bool registration)
12631263

12641264
if (registration)
12651265
{
1266-
if (pg_strcasecmp(cmdLine+strlen(cmdLine)-4,".exe"))
1266+
if (pg_strcasecmp(cmdLine+strlen(cmdLine)-4,".exe")!=0)
12671267
{
12681268
/* If commandline does not end in .exe, append it */
12691269
strcat(cmdLine,".exe");
@@ -1841,25 +1841,24 @@ set_mode(char *modeopt)
18411841
staticvoid
18421842
set_sig(char*signame)
18431843
{
1844-
if (!strcmp(signame,"HUP"))
1844+
if (strcmp(signame,"HUP")==0)
18451845
sig=SIGHUP;
1846-
elseif (!strcmp(signame,"INT"))
1846+
elseif (strcmp(signame,"INT")==0)
18471847
sig=SIGINT;
1848-
elseif (!strcmp(signame,"QUIT"))
1848+
elseif (strcmp(signame,"QUIT")==0)
18491849
sig=SIGQUIT;
1850-
elseif (!strcmp(signame,"ABRT"))
1850+
elseif (strcmp(signame,"ABRT")==0)
18511851
sig=SIGABRT;
1852-
1853-
/*
1854-
* probably should NOT provide SIGKILL
1855-
*
1856-
* else if (!strcmp(signame,"KILL")) sig = SIGKILL;
1857-
*/
1858-
elseif (!strcmp(signame,"TERM"))
1852+
#if0
1853+
/* probably should NOT provide SIGKILL */
1854+
elseif (strcmp(signame,"KILL")==0)
1855+
sig=SIGKILL;
1856+
#endif
1857+
elseif (strcmp(signame, "TERM")==0)
18591858
sig=SIGTERM;
1860-
elseif (!strcmp(signame,"USR1"))
1859+
elseif (strcmp(signame, "USR1")==0)
18611860
sig=SIGUSR1;
1862-
elseif (!strcmp(signame,"USR2"))
1861+
elseif (strcmp(signame, "USR2")==0)
18631862
sig=SIGUSR2;
18641863
else
18651864
{

‎src/bin/pg_dump/pg_dump.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14384,7 +14384,7 @@ myFormatType(const char *typname, int32 typmod)
1438414384
}
1438514385

1438614386
/* Show lengths on bpchar and varchar */
14387-
if (!strcmp(typname,"bpchar"))
14387+
if (strcmp(typname,"bpchar")==0)
1438814388
{
1438914389
intlen= (typmod-VARHDRSZ);
1439014390

@@ -14393,14 +14393,14 @@ myFormatType(const char *typname, int32 typmod)
1439314393
appendPQExpBuffer(buf,"(%d)",
1439414394
typmod-VARHDRSZ);
1439514395
}
14396-
elseif (!strcmp(typname,"varchar"))
14396+
elseif (strcmp(typname,"varchar")==0)
1439714397
{
1439814398
appendPQExpBuffer(buf,"character varying");
1439914399
if (typmod!=-1)
1440014400
appendPQExpBuffer(buf,"(%d)",
1440114401
typmod-VARHDRSZ);
1440214402
}
14403-
elseif (!strcmp(typname,"numeric"))
14403+
elseif (strcmp(typname,"numeric")==0)
1440414404
{
1440514405
appendPQExpBuffer(buf,"numeric");
1440614406
if (typmod!=-1)

‎src/bin/psql/tab-complete.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2368,7 +2368,7 @@ psql_completion(char *text, int start, int end)
23682368

23692369
/* Complete LOCK [TABLE] <table> with "IN" */
23702370
elseif ((pg_strcasecmp(prev2_wd,"LOCK")==0&&
2371-
pg_strcasecmp(prev_wd,"TABLE"))||
2371+
pg_strcasecmp(prev_wd,"TABLE")!=0)||
23722372
(pg_strcasecmp(prev2_wd,"TABLE")==0&&
23732373
pg_strcasecmp(prev3_wd,"LOCK")==0))
23742374
COMPLETE_WITH_CONST("IN");

‎src/interfaces/ecpg/ecpglib/data.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,19 @@ get_float8_nan(void)
9797
staticbool
9898
check_special_value(char*ptr,double*retval,char**endptr)
9999
{
100-
if (!pg_strncasecmp(ptr,"NaN",3))
100+
if (pg_strncasecmp(ptr,"NaN",3)==0)
101101
{
102102
*retval=get_float8_nan();
103103
*endptr=ptr+3;
104104
return true;
105105
}
106-
elseif (!pg_strncasecmp(ptr,"Infinity",8))
106+
elseif (pg_strncasecmp(ptr,"Infinity",8)==0)
107107
{
108108
*retval=get_float8_infinity();
109109
*endptr=ptr+8;
110110
return true;
111111
}
112-
elseif (!pg_strncasecmp(ptr,"-Infinity",9))
112+
elseif (pg_strncasecmp(ptr,"-Infinity",9)==0)
113113
{
114114
*retval=-get_float8_infinity();
115115
*endptr=ptr+9;

‎src/interfaces/ecpg/ecpglib/descriptor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ ECPGdeallocate_desc(int line, const char *name)
652652
ecpg_init_sqlca(sqlca);
653653
for (desc=get_descriptors(),prev=NULL;desc;prev=desc,desc=desc->next)
654654
{
655-
if (!strcmp(name,desc->name))
655+
if (strcmp(name,desc->name)==0)
656656
{
657657
if (prev)
658658
prev->next=desc->next;

‎src/interfaces/ecpg/ecpglib/execute.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,9 +1650,9 @@ ecpg_execute(struct statement * stmt)
16501650
ecpg_log("ecpg_execute on line %d: OK: %s\n",stmt->lineno,cmdstat);
16511651
if (stmt->compat!=ECPG_COMPAT_INFORMIX_SE&&
16521652
!sqlca->sqlerrd[2]&&
1653-
(!strncmp(cmdstat,"UPDATE",6)
1654-
||!strncmp(cmdstat,"INSERT",6)
1655-
||!strncmp(cmdstat,"DELETE",6)))
1653+
(strncmp(cmdstat,"UPDATE",6)==0
1654+
||strncmp(cmdstat,"INSERT",6)==0
1655+
||strncmp(cmdstat,"DELETE",6)==0))
16561656
ecpg_raise(stmt->lineno,ECPG_NOT_FOUND,ECPG_SQLSTATE_NO_DATA,NULL);
16571657
break;
16581658
casePGRES_COPY_OUT:

‎src/interfaces/ecpg/ecpglib/prepare.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ SearchStmtCache(const char *ecpgQuery)
361361
{
362362
if (stmtCacheEntries[entNo].stmtID[0])/* check if entry is in use*/
363363
{
364-
if (!strcmp(ecpgQuery,stmtCacheEntries[entNo].ecpgQuery))
364+
if (strcmp(ecpgQuery,stmtCacheEntries[entNo].ecpgQuery)==0)
365365
break;/* found it*/
366366
}
367367
++entNo;/* incr entry #*/

‎src/interfaces/ecpg/preproc/descriptor.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ drop_descriptor(char *name, char *connection)
106106

107107
for (i=descriptors;i;lastptr=&i->next,i=i->next)
108108
{
109-
if (!strcmp(name,i->name))
109+
if (strcmp(name,i->name)==0)
110110
{
111111
if ((!connection&& !i->connection)
112112
|| (connection&&i->connection
113-
&&!strcmp(connection,i->connection)))
113+
&&strcmp(connection,i->connection)==0))
114114
{
115115
*lastptr=i->next;
116116
if (i->connection)
@@ -135,11 +135,11 @@ lookup_descriptor(char *name, char *connection)
135135

136136
for (i=descriptors;i;i=i->next)
137137
{
138-
if (!strcmp(name,i->name))
138+
if (strcmp(name,i->name)==0)
139139
{
140140
if ((!connection&& !i->connection)
141141
|| (connection&&i->connection
142-
&&!strcmp(connection,i->connection)))
142+
&&strcmp(connection,i->connection)==0))
143143
returni;
144144
}
145145
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp